home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / ace23.lha / DOCS.lha / ace.doc < prev    next >
Text File  |  1994-10-22  |  105KB  |  2,929 lines

  1.  
  2.                 +----------+
  3.                 | ACE v2.3 |
  4.                 +----------+
  5.  
  6.  
  7.       CONTENTS                       LINE  PAGE
  8.       --------                        ----  ----
  9.  
  10.   (i)   Introduction
  11.  
  12.     What is ACE?..................................95     2
  13.     Who is it for?...............................185     4
  14.  
  15.     ------------------------------------------------
  16.  
  17.  (ii)    Getting started
  18.  
  19.     Installation.................................236     4
  20.     Using the compiler...........................315     6
  21.     Compiler options.............................359     6
  22.     Running ACE programs.........................450     8
  23.     About the example programs...................458     8
  24.  
  25.     ------------------------------------------------
  26.  
  27.  (iii)  A hitch-hiker's guide to ACE 
  28.  
  29.     General comments.............................490     9
  30.  
  31.     The preprocessor and #include files..........529     9
  32.  
  33.     Data types, expressions, constants...........572    10
  34.     Precedence of operators......................667    11
  35.     Indirection operators........................699    12
  36.     Identifiers..................................738    13
  37.  
  38.     Files........................................875    15
  39.  
  40.     Command-line and Workbench arguments.........969    16
  41.  
  42.     Subprograms.................................1020    17
  43.     Structures..................................1245    21
  44.     Shared library function calls...............1398    23
  45.     Machine code calls..........................1548    26
  46.  
  47.     External references.........................1620    27
  48.     Creating & using ACE subprogram modules.....1682    28
  49.         
  50.     Windows.....................................1879    31
  51.     Screens.....................................1907    32
  52.  
  53.     Gadgets.....................................1959    33
  54.     Menus.......................................2072    34
  55.     Requesters..................................2102    35
  56.  
  57.     Turtle Graphics.............................2124    35
  58.     Loading & displaying IFF pictures...........2248    37
  59.  
  60.  
  61.                                   - page 1 -
  62.  
  63.     Sound.......................................2268    38
  64.  
  65.     Event trapping..............................2359    39
  66.  
  67.     Interprocess Communication..................2449    41
  68.  
  69.     Error handling..............................2472    41
  70.  
  71.     Notes for assembly programmers..............2507    42
  72.  
  73.     Limitations.................................2552    42
  74.     Known bugs..................................2621    43
  75.  
  76.     ------------------------------------------------
  77.  
  78. (iv)    Stop bits
  79.  
  80.     Future versions.............................2638    44
  81.     A note to PD libraries and reviewers........2670    44
  82.  
  83.     Disclaimer..................................2691    45
  84.  
  85.     References..................................2698    45
  86.  
  87.     Contacting the author.......................2738    45
  88.     ACE discussion list and FTP site............2762    46
  89.  
  90.     Final word..................................2802    46
  91.  
  92.         ================================================
  93.  
  94.  
  95. What is ACE?
  96. ------------
  97.  AmigaBASIC Compiler with Extras?
  98.  A Creative Environment? 
  99.  A Compiler for Everyone?
  100.  A Cool Enterprise?
  101.  Automatic Computing Engine (ala Alan Turing)?
  102.  Dr Who's last companion?  
  103.  
  104. Okay, seriously...
  105.  
  106. ACE is a freely distributable, recursive descent, peephole-optimising Amiga 
  107. BASIC compiler which produces A68K-compatible assembly source code. ACE runs 
  108. under Wb 1.3, 2.x and up, as do the executables it produces. ACE will run
  109. in 512K, but more than this is required for programs beyond about 250 lines.
  110.  
  111. ACE supports a large subset of AmigaBASIC. It also provides a variety of 
  112. commands, functions and features not found in AmigaBASIC.
  113.  
  114. In many cases, ACE programs produce results which are similar or identical 
  115. to programs written in AmigaBASIC.
  116.  
  117. Any differences between the two are discussed in this document and the 
  118. command and function reference (ref.doc).
  119.  
  120. The following files constitute a complete ACE package:
  121.  
  122.                                   - page 2 -
  123.  
  124.  
  125.         executables
  126.         -----------      
  127.     bas        - A shell script which automates
  128.                 the production of ACE executables
  129.               (1.3 and 2.x/3.x versions).
  130.     app        - A simple preprocessor.
  131.     ace        - The BASIC compiler.
  132.     a68k        - Charlie Gibbs' 68000 assembler.
  133.     blink        - The Software Distillery's linker.
  134.     muchmore    - The file viewer by Fridtjof Siebert & Christian 
  135.               Stiens (1.3 and 2.x/3.x versions).
  136.  
  137.      documents
  138.     ---------        
  139.     ace.doc/guide    - The document you are reading, which describes ACE.
  140.     ref.doc/guide     - A command and function reference for ACE.
  141.     example.guide    - Examples of ACE command and function usage.
  142.     history        - A history of ACE's development.
  143.     a68k.doc    - Documentation for the assembler.
  144.     blink.doc    - Documentation for the linker.
  145.  
  146.     scanned libraries (NOT shared libraries)
  147.     -----------------
  148.     ami.lib        - A freely distributable version of amiga.lib.
  149.     startup.lib    - A library of routines needed at the start and
  150.               end of an ACE program run.
  151.     db.lib        - A library of assorted routines used by ACE
  152.               programs.
  153.  
  154.     other stuff
  155.     -----------
  156.     includes    - Some useful ACE include files. 
  157.     icons        - ACE tool and document icons.
  158.     utils        - Miscellaneous utilities.
  159.     examples    - Example programs which demonstrate many of ACE's 
  160.               capabilities.
  161.      AIDE        - A graphical front-end for ACE.
  162.  
  163. With one exception (see the discussion of file requesters under Wb 1.3 in 
  164. the "Requesters" section) ACE programs do not require any special run-time 
  165. shared libraries, so the executables which the compiler produces (via the 
  166. assembler and linker) are completely portable, requiring only the standard 
  167. Amiga shared libraries in your LIBS: directory. The three ".lib" files 
  168. mentioned above are scanned libraries and code from these is included at 
  169. link time.
  170.  
  171. ACE is written in C (Sozobon's ZC v1.01), while db.lib and startup.lib are 
  172. written in assembler (~50%) and C. I may eventually switch to SAS C.
  173.  
  174. A68K and Blink are used to assemble and link the code produced by ACE.
  175.  
  176. The MicroEmacs (v1.3 & v2.1) editor has been used throughout every stage
  177. of ACE's development. It works for me.
  178.  
  179. The complete ACE package may be freely distributed.
  180.  
  181.  
  182.  
  183.                                   - page 3 -
  184.  
  185. Who is it for?
  186. --------------
  187. ACE is intended for anyone who already knows BASIC and wants one or more of
  188. the following:
  189.  
  190.     - Faster program execution.
  191.  
  192.     - Independence from the BASIC interpreter, ie: standalone 
  193.       programs which are runnable from the CLI/Shell and Workbench.
  194.  
  195.     - Extra commands, functions and features: turtle graphics,
  196.       command-line (and Workbench) arguments, recursion, SUBs with 
  197.       return values, external references, named constants, structures, 
  198.       include files, better WAVE command, gadgets, requesters, ability
  199.       to create subprogram libraries, interprocess communication, etc.
  200.  
  201. Maybe you don't wish to learn another high-level language, or perhaps you 
  202. already use C or assembler but prefer to use BASIC for some tasks while 
  203. still having the power of a compiled language.
  204.  
  205. ACE is a general purpose language so in theory at least, it can be applied
  206. to any programming task you like. In practice however, I find ACE to be most
  207. useful for writing small to medium sized programs where speed is important 
  208. but so is ease of programming.
  209.  
  210. ACE is also a useful prototyping language. It allows you to get something 
  211. up and running quickly to test an idea. You may later decide to re-code in 
  212. C or assembler, or you may just add some polish to the existing ACE program.
  213.  
  214. The latter is becoming more feasible as ACE matures.
  215.  
  216. Here are some programs that have been written with ACE:
  217.  
  218.     - Shell utilities, eg: basic calculator (ACE:prgs/ShellUtils/bc.b).
  219.     - An 8SVX sound sample player.
  220.     - Fractal graphics programs.
  221.     - Neural networks.
  222.     - Astronomy programs, eg: galaxy collision simulator,
  223.       Jovian satellite position predictor, Messier object database.
  224.     - An Integrated Development Environment (AIDE - see separate
  225.       archive).        
  226.     - A home security/wakeup system.
  227.     - A program which matches section headings to line and page 
  228.       numbers to create the document you are now reading from an
  229.       unformatted version of it.
  230.     - A Workbench calculator with a difference.
  231.     - A SpiroGraph simulator (Chuck Kenney).
  232.     - A serial Stratego game (Dan Oberlin).
  233.     - A variety of communications programs.
  234.     
  235.  
  236. Installation
  237. ------------
  238. You will need to open a shell to install ACE. Installation consists of:
  239.  
  240.     - Extracting the four archives found in the single supplied ACE 
  241.       archive.
  242.  
  243.  
  244.                                   - page 4 -
  245.  
  246.     - Adding a few commands to your s:user-startup (Wb 2.x/3.x) or 
  247.       s:startup-sequence (Wb 1.3) file.
  248.  
  249. The distribution archive contains:
  250.  
  251.     - MAIN.lha        (main ACE files with a few examples)
  252.     - DOCS.lha        (documentation for ACE,A68K and Blink)
  253.     - PRGS.lha        (more example programs)
  254.     - AIDE.lha        (a graphical front-end for ACE)
  255.  
  256. All four will fit onto a single floppy disk in their compressed form.
  257.  
  258. So, extract these four archives into RAM:, into a temporary hard disk 
  259. directory or onto an empty floppy disk with:
  260.  
  261.     lha x <ACE-archive>        
  262. eg.
  263.     lha x ACE23
  264.  
  265. You must now extract the files from each archive with:
  266.  
  267.     lha -a x <archive>
  268. eg.
  269.     lha -a x MAIN
  270.  
  271. The "-a" switch preserves file attributes (eg. the "s" bit on shell scripts) 
  272. in the archive.
  273.  
  274. If you have a hard disk, just extract all four archives into a directory
  275. created for ACE (eg: sys:ACE). Extract MAIN.lha first. This will set up the 
  276. directory structure and main ACE files.
  277.  
  278. The extraction of MAIN.lha also creates three subdirectories for the last 
  279. three archives. Extract DOCS.lha, PRGS.lha and AIDE.lha into the docs, prgs 
  280. and AIDE subdirectories.
  281.  
  282. If you are using a floppy-only system, extract MAIN.lha onto one disk and 
  283. the last three archives onto other disks to suit yourself. The disk on which 
  284. the main ACE files reside is the volume to which the shell commands discussed 
  285. below refer.
  286.  
  287. Next, add the following lines to your user-startup or startup-sequence 
  288. script:
  289.  
  290.     assign ACE: <volume or directory>
  291.     path ACE:bin add
  292.  
  293. where <volume or directory> is the name of the disk or directory where
  294. the main ACE files now reside (eg: assign ACE: sys:ACE).
  295.  
  296. In addition, you need to add three more statements to your startup-sequence
  297. or user-startup script:
  298.  
  299.     assign ACElib:       ACE:lib    ; bas finds scanned libraries here.
  300.     assign ACEbmaps:   ACE:bmaps    ; ace looks here for .bmap files.
  301.     assign ACEinclude: ACE:include    ; app uses this for include files.
  302.  
  303. Now reboot your Amiga to let the above path and assign commands take effect.
  304.  
  305.                                   - page 5 -
  306.  
  307.  
  308. That's it!
  309.  
  310. ** Note: As an alternative to these startup script modifications, you can 
  311. use the "ACEsetup" script to be found in MAIN.lha. Read the comments at 
  312. the top of that script for usage details.
  313.  
  314.  
  315. Using the compiler
  316. ------------------
  317. Starting with ACE v2.0 there are two ways to use the compiler:
  318.  
  319.     - From the shell/CLI.
  320.     - Via an Integrated Development Environment: AIDE.
  321.  
  322. Whichever environment you choose to work with ACE in, read on.
  323.  
  324. ACE expects all BASIC source files to have a ".b" or ".bas" extension.
  325.  
  326. If you have a program called foo.b[as], you would invoke the compiler thus:
  327.  
  328.     ace foo    (or ace foo.b[as])
  329.  
  330. This would produce foo.s, an A68K-compatible assembly source (text) file.
  331.  
  332. If you wanted to preprocess, compile, assemble and link foo.b[as], you'd 
  333. type:
  334.  
  335.     bas foo
  336.  
  337. which would yield foo (the executable).
  338.  
  339. The bas script sets the stack to 40000 bytes. Before running ACE by itself,
  340. you will need to set this. A minimum stack size seems to be around 5000
  341. for many ACE compilations, but I recommend 40000 to be safe.
  342.  
  343. If your Amiga GURUs or hangs during a compile or produces garbage in the 
  344. shell, you can be confident that the stack is too small.
  345.  
  346. You can either create a BASIC source file using an editor or in the AmigaBASIC 
  347. environment. If you want to compile a program developed with the interpreter,
  348. just save the program in ASCII format thus:
  349.  
  350.     save "foo.b[as]",a
  351.  
  352. ACE will only compile ASCII source files, not AmigaBASIC's compressed format.
  353.  
  354. For those who don't have access to the AmigaBASIC interpreter but who wish
  355. to convert old AmigaBASIC programs not saved in ASCII format, see the 
  356. ACE:utils directory for a utility called ab2ascii written by Stefan Reisner.
  357.  
  358.  
  359. Compiler options
  360. ----------------
  361. The full command line syntax for ACE is:
  362.  
  363.     ace [words | -bcEilmOw] <sourcefile>[.b[as]]
  364.  
  365.  
  366.                                   - page 6 -
  367.  
  368. which indicates that there are currently eight optional compiler switches. 
  369.  
  370. Before giving a description of these switches however, let me say something
  371. about the optional "words" parameter. If the command:
  372.  
  373.     ace words
  374.  
  375. is given, all the reserved words which are known to the compiler will be
  376. dumped to standard output (ie. to the shell/CLI). Using redirection thus:
  377.  
  378.     ace words > rwords
  379.  
  380. will result in a file containing this information. This feature will be
  381. useful for anyone wanting to know which words are reserved by the compiler. 
  382. AmigaBASIC and ACE keywords are differentiated.
  383.  
  384. The switches can appear in any combination (eg: -bO, -clb, -O, -ObE) but 
  385. they *are* case sensitive (so -b does not equal -B).
  386.  
  387. The "b" switch tells the compiler to include code to check for ctrl-c breaks 
  388. by the user. The inclusion of this code can result in noticeably larger
  389. assembly source files, but execution speed doesn't seem to suffer appreciably.
  390. When a ctrl-c is detected, the program will clean up and exit but user-defined
  391. windows and screens will remain open. The use of ON BREAK can get around this 
  392. by allowing for user-controlled clean up (see the "Event Trapping" section
  393. below). See also the "w" switch.
  394.  
  395. The "c" switch includes each line of ACE source code as a comment in the
  396. final assembly source file. This was requested as a debugging aid. Warning:
  397. the presence of such comments interferes with peephole optimisation. Also be
  398. aware that ACE sometimes includes extra code apart from that which you might
  399. expect purely on the basis of the source code.
  400.  
  401. The "E" switch creates a file in the current directory called ace.err which
  402. contains all error messages generated during a compliation. Error messages
  403. are still displayed to the screen during compilation however.
  404.  
  405. The "i" switch tells ACE to make an icon for the executable resulting from 
  406. the compilation. The file "ACE:icons/exe.info" must exist as it is used as
  407. the source file for the icon. This allows you to use an icon of your own if
  408. you so wish.
  409.  
  410. The "l" switch causes the compiler to display each line of ACE source code 
  411. as it is being compiled.
  412.  
  413. The "m" switch creates a linkable module containing no startup code (See
  414. "Creating & using ACE subprogram modules" section below).
  415.  
  416. The "O" switch causes the assembly source code produced by ACE to be optimised.
  417. A range of peephole optimisations is currently carried out. Assembly code size
  418. reductions of around 5% to 10% are usual. Speed improvements vary, depending
  419. upon the program, however I recommend the use of the -O switch for all programs
  420. where speed is the least bit important. ACE's optimiser has been improved since 
  421. v2.0 and it will continue to be improved.
  422.  
  423. The "w" switch tells ACE to include checks for window close-gadget clicks.
  424. ACE checks all open windows and upon detecting a close-gadget click, the
  425. clicked window is closed and the program exits. However, any other open
  426.  
  427.                                   - page 7 -
  428.  
  429. windows or screens will not be closed. The use of ON WINDOW can get around 
  430. this by allowing for a user-defined clean-up subroutine (see the "Event 
  431. Trapping" section below).
  432.  
  433. See also the OPTION command in ref.doc.
  434.  
  435. The syntax for the bas script is:
  436.  
  437.     bas [-bcEilmOw] <sourcefile> [<objectfile>]
  438.  
  439. where <sourcefile> is the program to be compiled (without the .b[as] 
  440. extension) and <objectfile> is a C, assembly or ACE module which has been 
  441. (compiled and) assembled to produce an object file.
  442.  
  443. The <objectfile> is linked with the output of ACE+A68K along with db.lib, 
  444. startup.lib and ami.lib. This is necessary when an external function or 
  445. variable in <objectfile> is referenced by an ACE program. For more about 
  446. external functions, see the sections "External references" and "Creating & 
  447. using ACE subprogram modules" below.
  448.  
  449.  
  450. Running ACE programs
  451. --------------------
  452. ACE programs can be run from either a shell/CLI or Workbench. In the latter
  453. case a tool icon must be created for the executable. One has been provided
  454. with the archive in the icons directory (exe.info). Refer to the "i" switch 
  455. in "Compiler options" above re: automatic icon creation by the compiler.
  456.  
  457.  
  458. About the example programs
  459. --------------------------
  460. I have written a number of programs which illustrate most of the features
  461. of ACE up to this point and you should find these with the distribution.
  462.  
  463. Several programs are related to chaos theory and fractals. The remainder 
  464. are an assorted bunch which demonstrate ACE's capabilities.
  465.  
  466. The information for the chaos/fractal programs came from a wide variety of 
  467. sources. The algorithms for henon.b and lorenz.b came from "Dynamical systems 
  468. and fractals: computer graphics experiments in Pascal" by Becker & Dorfler, 
  469. 1990.
  470.  
  471. Some programs are optimised at the source level and some are not. You'll 
  472. find that using integer variables can often result in quite dramatic 
  473. improvements in program execution speed (eg: try replacing op% with op! and 
  474. k% with k! in ifs.b and you'll see what I mean).
  475.  
  476. There are several examples which demonstrate the use of recursive 
  477. subprograms in ACE (eg: misc/fact.b).
  478.  
  479. Another area of interest for me is neural networks and you'll find a 
  480. program called gfx/hopnet.b, which shows graphically how a simple Hopfield 
  481. network changes under various conditions.
  482.  
  483. Other programs include a talking clock (tclock.b), a sound sample player 
  484. (sound/play.b) and a command-line calculator (ShellUtils/bc.b).
  485.  
  486.  
  487.  
  488.                                   - page 8 -
  489.  
  490. General comments
  491. ----------------
  492. I made a decision very early on in the project to allow standard I/O (for 
  493. shell/CLI). All other windows are (as of ACE v2.0) Intuition windows.
  494.  
  495. The execution speed of most programs (especially with graphics, eg: ifs.b)
  496. is, as you might expect, *fast* compared to interpreted AmigaBASIC.
  497.   
  498. No error messages are given at run-time (but some errors are reported via ERR
  499. and ON ERROR), nor is there any stack overflow or array bounds checking. 
  500.  
  501. Labels are supported and can be used with GOSUB and GOTO. Line numbers are 
  502. supported, but are only necessary for old BASIC programs. Also, ACE's rich 
  503. assortment of control constructs makes the use of GOTO largely redundant.
  504.  
  505. Available control constructs are: WHILE..WEND, REPEAT..UNTIL, IF..THEN..ELSE,
  506. IF..THEN..ELSE..END IF, CASE..END CASE, ON..GOTO, ON..GOSUB, SUB..END SUB and 
  507. GOSUB..RETURN.
  508.  
  509. Apart from single line comments with REM and ' ACE allows block comments with
  510. { and }. For example:
  511.  
  512.  { comments can span more than 
  513.    one line like this }
  514.  
  515. Multi-statements are also supported by ACE - as they are in AmigaBASIC, eg:
  516.  
  517.  x$="hello":y$="there":say translate$(x$+" "+y$)
  518.  
  519. In ACE (as in AmigaBASIC) end-of-line characters (ASCII 10) are significant,
  520. so a line continuation character (~) must be used to extend expressions and
  521. parameter lists (etc) over more than one line, eg.
  522.  
  523.  DECLARE FUNCTION MyAmazingExternalFunction(theFirst, theSecond, theThird, ~
  524.                         theFourth) EXTERNAL
  525.  
  526. Note that this feature is ACE-specific.
  527.  
  528.  
  529. The preprocessor and #include files
  530. ------------------------------------
  531. The ACE preprocessor: APP, is modest when compared to the C preprocessor.
  532.  
  533. Its main function thus far is for the inclusion of files with the #include 
  534. directive. As in C, #include "filename" looks for the file as specified, 
  535. while #include <filename> looks for the file in a local include directory 
  536. (see "Installation"). A file will only ever be included once.
  537.  
  538. The #include directive can also be used in included files, but since file 
  539. inclusion is recursive, watch your stack size (40000 bytes is plenty).
  540.  
  541. APP also handles single-line comments (text following a "'") and block
  542. comments (starting with "{" and ending with "}"). This is partly to allow
  543. #include commands to be commented out and also to make less work for the 
  544. compiler. However, the compiler does still handle comments in case the pre-
  545. processor isn't invoked. APP does not handle REM since this is a BASIC 
  546. statement.
  547.  
  548.  
  549.                                   - page 9 -
  550.  
  551. The syntax for APP is: 
  552.  
  553.     app <source> <dest> 
  554.  
  555. The bas script uses APP by first preprocessing an ACE source file to the
  556. RAM:T directory.
  557.  
  558. Use of #include has the effect of adding lines to the preprocessed ACE 
  559. source, which has an impact upon the physical location of lines from the
  560. main ACE file when transfered to the destination file.
  561.  
  562. ACE include files have two purposes. As in C they can be used to include
  563. constants and structure definitions. Second, as with files like WBarg.h,
  564. ACE include files may contain subprogram definitions and although this is 
  565. quite possible in C, it seems to be less often done under the guise of .h 
  566. files. I have arbitrarily chosen to append all include files with .h but 
  567. there is no reason why this need be so. Purists will probably be aghast.
  568.  
  569. APP will be improved as time goes by.
  570.   
  571.  
  572. Data types, expressions and constants
  573. ------------------------------------- 
  574. The following fundamental data types are currently supported:
  575.  
  576.     - signed short integers (2 bytes = 16 bits)
  577.     - signed long integers  (4 bytes = 32 bits)
  578.     - single-precision: Motorola fast floating point (4 bytes = 32 bits)
  579.     - strings (default to 1024 bytes including ASCII 0 at end of string) 
  580.  
  581. Exponential and fixed-point formats are recognised by all ACE functions
  582. and in program text for single-precision numbers.
  583.  
  584. Expression parsing is the same as for AmigaBASIC, as is the precedence of 
  585. operators. Evaluation of _all_ expressions proceeds from left to right.
  586. This includes exponentiation, so 2^3^2 will be evaluated as (2^3)^2.
  587.  
  588. In addition, due to the higher precedence of exponentiation over unary 
  589. negation and the way ACE's recursive descent parser works, 4^(-2) is okay, 
  590. but 4^-2 isn't.
  591.  
  592. ACE supports full 32-bit and single-precision floating point math:
  593.  
  594.     addition, subtraction, multiplication:
  595.         
  596.         - 16-bit integer
  597.         - 32-bit integer
  598.         - single-precision 
  599.  
  600.     division & modulo arithmetic:
  601.  
  602.         - 32-bit integer
  603.         - single-precision
  604.  
  605. Increment and decrement operators are provided in ACE in the following form:
  606.  
  607.     ++<variable> OR --<variable>
  608.  
  609.  
  610.                                   - page 10 -
  611.  
  612. The value of the simple or external variable is incremented or decremented 
  613. by 1.
  614.  
  615. Notice that ++ and -- are pre-increment & pre-decrement operators ONLY. Those 
  616. familiar with C will recognise these operators and their utility. In terms of 
  617. efficiency: ++x is better than x=x+1.  
  618.                     
  619. Unlike interpreted AmigaBASIC, hexadecimal and octal constants can be either 
  620. short or long values. This makes for nicer addressing with PEEK & POKE. Also,
  621. the prefixes &H and &O may precede an integer anywhere that it makes sense,
  622. including in strings submitted to the VAL function. The effect of &H and &O
  623. is to indicate that a hexadecimal or octal value follows. The use of these 
  624. prefixes is consistent with AmigaBASIC.
  625.  
  626. Trailing characters (%&!#) after constants cause coercion from one numeric
  627. data type to another, as in AmigaBASIC, eg:
  628.     
  629.     Delay(50&)   '..50 is coerced from short to long integer
  630.     x=12.5*65!   '..65 is coerced from short integer to single-precision
  631.  
  632. Using these type-qualifier characters means that ACE doesn't have to generate
  633. numeric conversion code. This leads to smaller assembly code source files.
  634.  
  635. As in AmigaBASIC expression evaluation, all operands in an expression are 
  636. converted to the data type of the most precise operand. Logical operators 
  637. (AND,EQV,IMP,NOT,OR,XOR) convert their operands to integer values as does 
  638. the integer division operator "\". Relational operators (= <> > < >= <=) 
  639. yield long integer results.  
  640.   
  641. ACE's boolean values are as follows: 0=false, N=true where N is any 
  642. non-zero long integer. Note that relational operations give -1 for true 
  643. (since: NOT -1 = 0).
  644.  
  645. Please note that in addition to their use in relational expressions, the 
  646. logical operators (AND, NOT...) actually work in bitwise fashion. This means 
  647. that you can create bitwise AND masks and perform other operations on groups 
  648. of bits, as desired. The SHL and SHR functions may also prove useful in this 
  649. respect (see ref.doc).
  650.  
  651. ACE allows you to define named global signed numeric constants with the 
  652. CONST directive (see command and function reference).
  653.  
  654. Strings have a default length of 1K instead of the usual 32K, since ACE 
  655. programs reserve memory for each string immediately at run-time which could
  656. result in quite memory hungry executables if strings were too large. It is 
  657. possible however, to define strings which are longer or shorter than 1K (see 
  658. the STRING command).
  659.  
  660. ACE strings are NULL terminated, ie: the last character is an ASCII 0, as in
  661. strings manipulated by C's standard library functions.
  662.  
  663. A string literal without a final '"' will be truncated at the end of the 
  664. line.
  665.  
  666.  
  667. Precedence of operators
  668. -----------------------
  669. ACE follows AmigaBASIC in operator precedence, with the addition of structure 
  670.  
  671.                                   - page 11 -
  672.  
  673. dereferencing and indirection operators.
  674.  
  675.     Level    Operation/Operator                Symbol
  676.     -----    ------------------                ------
  677.  
  678.     1.      Structure Member Dereferencing,            ->
  679.             Parentheses and Address Operator        () @
  680.     2.      Indirection Operators                *% *& *!    
  681.     3.      Exponentiation                    ^
  682.     4.      Unary Negation                    -
  683.     5.      Multiplication and Floating-Point Division    * /
  684.     6.      Integer Division                \
  685.     7.      Modulo Arithmetic                MOD
  686.     8.      Addition and Subtraction            + -
  687.     9.      Relational Operators                = < > <= >= <>
  688.     10.     NOT
  689.     11.     AND
  690.     12.     OR and XOR
  691.     13.     EQV
  692.     14.     IMP
  693.  
  694. The use of parentheses in an expression forces the enclosed term to be 
  695. evaluated before adjacent terms. Expression evaluation always proceeds 
  696. from left to right in ACE and AmigaBASIC.
  697.  
  698.   
  699. Indirection operators
  700. ---------------------
  701. ACE has four indirection operators: @,*%,*&, and *!. These are _similar_
  702. to pointers in C.
  703.  
  704.     @<object>   - returns the absolute address of a data object.
  705.             - note that this is identical to VARPTR(<object>).
  706.     *%<address> - peeks or pokes a short value at the specified address.
  707.     *&<address> - peeks or pokes a long value at the specified address.
  708.     *!<address> - peeks or pokes a single value at the specified address.
  709.  
  710. The indirection operators can therefore be used in a statement (poke) and/or 
  711. as part of an expression (peek), for example:
  712.  
  713.     address x
  714.     y=23.25
  715.     x=@y
  716.     *!x := *!x + 2
  717.     print y
  718.  
  719. will print a value of 25.25.
  720.  
  721. There are two things to notice here. First, the pointers are to addresses, 
  722. not necessarily connected to variables. It would be quite legal to allocate
  723. an area of memory and then dereference it with these operators.
  724.  
  725. Second, when assigning a value to a dereferenced memory location as in the 
  726. above example, the ":=" symbol must be used, simply because of the way the 
  727. parser processes statements. Pascal programmers will recognise this as 
  728. the assignment operator. 
  729.  
  730. See also the section below for information about how to use these operators
  731.  
  732.                                   - page 12 -
  733.  
  734. to implement variable parameters (call-by-reference) for simple variables in 
  735. ACE subprograms.
  736.  
  737.  
  738. Identifiers
  739. -----------
  740. As in AmigaBASIC an identifier can consist of a combination of letters, 
  741. numbers and periods (".") up to a maximum length of 40 characters. 
  742.  
  743. In ACE the underscore ("_") character is also legal. An ACE identifier must 
  744. start with either a letter or an underscore character.
  745.  
  746. An identifier can be used to represent the following:
  747.  
  748.         - labels
  749.         - arrays
  750.         - variables
  751.         - parameters
  752.         - structures
  753.         - subprograms
  754.         - defined functions
  755.         - named constants
  756.         - shared library functions
  757.         - external functions and variables
  758.  
  759. Note that in ACE, a simple variable and an array with the same name
  760. cannot coexist. For example, a single-precision variable V cannot
  761. coexist with a single-precision array, eg: DIM V(100). However 'V!' *can*
  762. live with V(100) since V and V! are different variables in ACE. See the 
  763. discussion of qualifier characters below.
  764.  
  765. Labels are global in ACE, so a main program label and a SUB label cannot 
  766. have the same name. The format for a label definition is:
  767.  
  768.     <name>:
  769.  
  770. Labels are used by GOTO and GOSUB. For example:
  771.  
  772.     GOSUB HaveSomeFun
  773.     STOP
  774.  
  775.     HaveSomeFun:
  776.         PRINT "Are we having fun yet?"
  777.     RETURN
  778.         
  779. Identifiers can have a qualifier character (%&$!#) appended in order to 
  780. indicate data type, where:
  781.  
  782.         % = short integer
  783.         & = long integer
  784.         ! = single-precision
  785.         # = double-precision -> not supported yet
  786.         $ = string    
  787.  
  788. Examples of valid identifiers are:
  789.  
  790.         x3
  791.         num&
  792.  
  793.                                   - page 13 -
  794.  
  795.         _putchar
  796.         play.sound
  797.  
  798. An identifer with no qualifier has a default type of single-precision. The 
  799. DEFxxx compiler directives (see command and function reference) have the
  800. same effect as the qualifier characters except they affect all identifiers
  801. starting with a certain letter. Qualifier characters have higher priority
  802. than DEFxxx directives. 
  803.  
  804. For shared library functions and external references, a qualifier is used 
  805. merely to declare data type. So for example, an external function might be 
  806. declared thus:
  807.  
  808.         external function RangeRand%
  809.  
  810. but can later be referred to as RangeRand.
  811.  
  812. The declaration of external functions/variables and shared library functions
  813. is global no matter where the declaration occurs.
  814.  
  815. Defined constants are unaffected by qualifier characters. The _value_ of a 
  816. defined constant determines its type. Thus CONST x&=1.2 is a single-precision
  817. - NOT a long integer - constant. Needless to say therefore, it is unwise to
  818. use qualifier characters for named constants.
  819.  
  820. The declaration of constants (with CONST) is always global whether the
  821. declaration takes place in the main program or a subprogram.
  822.  
  823. Structure variables hold a long integer value (address), so trailing 
  824. characters have no effect.
  825.  
  826. Structure type definitions are global, but structure variable declarations
  827. are local.
  828.  
  829. ACE allows for *optional* variable declarations with the SHORTINT, LONGINT,
  830. ADDRESS, SINGLE and STRING directives. Such declarations are useful in that:
  831.     
  832.         (i)    They ensure that a variable has a NULL or zero 
  833.             value.
  834.  
  835.         (ii)    They prevent dangerous errors which result from 
  836.             the misspelling of variable names.
  837.  
  838.         (iii)    Most languages have them and they serve to 
  839.             document variable usage explicitly.
  840.  
  841.         (iv)    They provide a "cleaner" way of establishing a 
  842.             variable which is to be shared by a subprogram
  843.             in ACE.
  844.  
  845. My feeling on the matter of variable declarations is that in a small program 
  846. they probably aren't necessary so long as you are careful, but in a large 
  847. program all major variables should be declared for safety. I plan to add a
  848. compiler switch which could be used to enforce mandatory variable declarations.
  849.   
  850. Variable declarations override the DEFxxx compiler directives and qualifier
  851. characters and are local to the current level (main program or subprogram).
  852.  
  853.  
  854.                                   - page 14 -
  855.  
  856. Summary of identifier properties:
  857.  
  858. +---------------+---------------+------------------+
  859. | Identifier    | Local/Global  | Affected by %&!$ |
  860. +---------------+---------------+------------------+
  861. | ARRAY        | LOCAL        | YES            |
  862. | SIMPLE VAR    | LOCAL        | YES           |
  863. | STRUCTURE VAR | LOCAL        | NO           |            
  864. | PARAMETER    | LOCAL        | YES           |
  865. | STRUCTURE DEF | GLOBAL    | NO           |        
  866. | LABEL        | GLOBAL    | NO           |
  867. | NAMED CONST   | GLOBAL    | NO           |
  868. | SUBPROGRAM     | GLOBAL    | YES           |
  869. | DEF FN     | GLOBAL    | YES           |
  870. | LIBRARY FUNC  | GLOBAL    | YES (declaration)|
  871. | EXT VAR/FUNC    | GLOBAL    | YES (declaration)|
  872. +---------------+---------------+------------------+
  873.  
  874.    
  875. Files
  876. -----
  877. AmigaBASIC sequential files are supported and random files are on the list 
  878. of things to do.
  879.  
  880. The commands and functions for manipulating sequential files in ACE are:
  881.  
  882. commands:
  883.     - OPEN
  884.     - CLOSE
  885.     - PRINT#
  886.     - WRITE#
  887.     - INPUT#
  888.     - LINE INPUT#
  889.  
  890. functions:
  891.     - INPUT$ 
  892.     - EOF
  893.     - LOF
  894.     - HANDLE *
  895.  
  896.     * not found in AmigaBASIC
  897.  
  898. Note that for any command which is immediately followed by a # there should 
  899. be at least one space between the keyword and the #, even though I may refer 
  900. to such commands as <name># in the text of this document and in ref.doc.
  901.  
  902. See the command and function reference for details of each of these.
  903.  
  904. When WRITE# is used, the result is identical to AmigaBASIC. For example:
  905.  
  906.     X=12 : Y=-3.2 : Z$="fun eh?"
  907.     OPEN "O",#1,"stuff"
  908.       WRITE #1,X,Y,Z$
  909.     CLOSE #1
  910.  
  911. results in a one-line file of the following format:
  912.  
  913.     12,-3.2,"fun eh?"
  914.  
  915.                                   - page 15 -
  916.  
  917.  
  918. On the other hand, if the following is used instead: 
  919.  
  920.     PRINT #1,X,Y,Z$ 
  921.  
  922. the file format will be:
  923.  
  924.      12         -3.2        fun eh?
  925.  
  926. while if semicolons are used:
  927.  
  928.     PRINT #1,X;Y;Z$
  929.  
  930. the file format becomes:
  931.  
  932.      12 -3.2 fun eh?
  933.  
  934. INPUT# (eg: INPUT #1,X,Y,Z$) can be used to read values from a file in any 
  935. of the above formats, but bear in mind that strings that are not delimited
  936. by quotes, but contain spaces or tabs will be seen as more than one string 
  937. by INPUT#. So, in the example formats above, while 
  938.  
  939.     "fun eh?" 
  940.  
  941. is one string,
  942.  
  943.     fun eh?
  944.  
  945. is two strings as far as INPUT# is concerned.
  946.  
  947. The formats of sequential files in ACE and AmigaBASIC are now very nearly
  948. identical, the only differences being in ACE tabs (produced by comma 
  949. delimiters in PRINT -- see PRINT in ref.doc) and the number of decimal 
  950. places written for single-precision values (usually more in ACE).
  951.   
  952. If you find ACE file I/O too slow, you may want to use the dos.library 
  953. functions (eg: xRead, xWrite). For this reason, I have included the HANDLE 
  954. function which returns the AmigaDOS handle of a file opened with ACE's OPEN 
  955. command. You may also wish to use the ami.lib buffered file I/O functions 
  956. which also require this handle. If HANDLE returns 0, the file can't be opened.
  957.  
  958. See prgs/IO/print.b for an example of opening a sequential file to a printer. 
  959.  
  960. Although SER: may be opened as a sequential file, it is not possible to 
  961. specify parameters for the serial port (baud rate etc) by this method as 
  962. is possible in AmigaBASIC.
  963.  
  964. Instead, ACE provides a set of special serial I/O commands. See ref.doc for 
  965. details of SERIAL OPEN/CLOSE etc, and prgs/IO/aterm.b for a simple terminal 
  966. program.
  967.  
  968.  
  969. Command line and Workbench arguments
  970. ------------------------------------
  971. When invoked from a Shell or CLI, an ACE program may have arguments, eg:
  972.  
  973.     tree 30
  974.  
  975.  
  976.                                   - page 16 -
  977.  
  978. Arguments can be accessed by two ACE functions:
  979.  
  980.     ARGCOUNT and ARG$(n)
  981.  
  982. The former returns a short integer value indicating the number of arguments
  983. for the current program, while the latter returns the nth argument as a string
  984. where n ranges from 0 to argcount. The zeroth argument (ie: ARG$(0)) is the 
  985. name of the program.
  986.  
  987. Workbench arguments are currently supported by ACE in the form of four 
  988. functions in the include file WBarg.h: WBargcount, WBarg$(n), WBargPath$(n) 
  989. and WBargLock&(n).
  990.  
  991. The first three are the most useful. The fourth is mainly for use by 
  992. WBargPath$. 
  993.  
  994. WBargcount returns the number of arguments passed to a program. This includes
  995. the program name.
  996.  
  997. As with ARG$(0), the zeroth Workbench argument is the name of the program.
  998.  
  999. To pass arguments to a program via Workbench one of the shift keys is held 
  1000. down while the icons which represent the arguments to be passed are activated.
  1001. While still depressing the shift key, the application icon is double clicked. 
  1002.  
  1003. An alternative method of passing arguments is to change the default tool of a 
  1004. project icon (eg: document) with the Info option from Workbench.
  1005.  
  1006. When this project icon is double clicked, the default tool will be loaded.
  1007. In this case, if the source code of the default tool (the program) had a line 
  1008. such as:
  1009.  
  1010.     x$ = WBarg$(1)
  1011.  
  1012. x$ would contain the name of the project file.
  1013.  
  1014. WBargPath$(n) is used to find the full path of the file name and includes 
  1015. trailing ":" and "/" characters.
  1016.  
  1017. See the include file WBarg.h for further descriptions of each function.
  1018.  
  1019.       
  1020. Subprograms
  1021. -----------
  1022. Subprograms are supported by ACE, but differ from AmigaBASIC subprograms in
  1023. a number of ways. Namely, ACE subprograms:
  1024.  
  1025.     - Don't use the STATIC keyword,
  1026.     - Allow recursion,
  1027.        - Can be assigned return values.
  1028.  
  1029. ACE subprograms don't make use of the STATIC keyword because they are non
  1030. static. This means that between calls to a specific subprogram, variables
  1031. local to the subprogram cease to retain any meaningful value since the 
  1032. memory used to store them may be reused for other purposes.
  1033.  
  1034. Recursive subprograms are an important feature of modern general programming 
  1035. languages. For several examples of the use of recursion, see the included 
  1036.  
  1037.                                   - page 17 -
  1038.  
  1039. programs (eg: fact.b, hanoi.b, tree.b). See also ACEinclude:WBarg.h.
  1040.  
  1041. A word of warning about recursion: it can be stack hungry, so it's a good 
  1042. idea to set your stack to 20000 or so, just to be safe, although in most 
  1043. cases, this will be a lot more than you need. From Workbench, simply change 
  1044. the tool's stack size with Info, or with the STACK command in a shell.
  1045.  
  1046. As with AmigaBASIC, ACE subprogram declarations cannot be nested.
  1047.  
  1048. The syntax of a subprogram call is the same as in AmigaBASIC:
  1049.  
  1050.     [CALL] sub-name[(parameter-list)]
  1051.  
  1052. The only difference is that the parentheses around the parameter list are
  1053. not optional when CALL is omitted -- unless there are NO parameters. 
  1054.  
  1055. CALL *must* be used after THEN in a single-line IF..THEN statement.
  1056.  
  1057. By default, every subprogram has a return type of single-precision (just like 
  1058. variables). The DEFxxx directives can be used to change the default data type 
  1059. of subprograms, as can the trailing characters !#$&%. A subprogram name can
  1060. also be preceded by SHORTINT,LONGINT,ADDRESS,SINGLE or STRING as yet another
  1061. alternative to setting the subprogram's return type.
  1062.  
  1063. The fact that ACE subprograms can be easily used as functions pretty much 
  1064. obviates the need for DEF FN. However for reasons of compatibility with 
  1065. AmigaBASIC and other BASICs, as well as its utility for simple functions, 
  1066. ACE supports DEF FN (as of ACE v2.0). 
  1067.  
  1068. A subprogram is given a value either inside the body of the relevant 
  1069. subprogram or in the main program (eg: to zero it) - ala Pascal - thus:
  1070.  
  1071.     sub-name = <expression>
  1072.  
  1073. However, subprograms cannot be assigned a value in any other way (eg: with
  1074. INPUT or READ).
  1075.  
  1076. A subprogram can be used in an expression, whereupon the subprogram is called
  1077. and its value pushed onto the stack for inclusion in the final result of the
  1078. expression, eg:
  1079.  
  1080.     x = n*pow(n)
  1081.  
  1082. where "pow" is a subprogram with one parameter.
  1083.  
  1084. While subprogram declarations can appear anywhere within the program text,
  1085. ACE requires that declarations precede calls. So:
  1086.  
  1087.     sub test
  1088.       print "hello"
  1089.      end sub
  1090.  
  1091.     test
  1092.  
  1093. is legal, but:
  1094.  
  1095.     test
  1096.  
  1097.  
  1098.                                   - page 18 -
  1099.  
  1100.     sub test
  1101.       print "hello"
  1102.      end sub
  1103.  
  1104. is not, and will yield an "undeclared subprogram" error. To get around this, 
  1105. a forward declaration can be used:
  1106.  
  1107.     declare sub test
  1108.     
  1109.     test
  1110.  
  1111.     sub test
  1112.       print "hello"
  1113.     end sub
  1114.  
  1115. Forward declarations can include a parameter list. If you later declare
  1116. the actual SUB with a different parameter list and you've already called 
  1117. the subprogram after a forward declaration, the results will be unpredictable.
  1118. I may place tighter controls on this at some stage.
  1119.  
  1120. Actual parameters are checked for number and type against formals, and 
  1121. parameter count mismatches result in a compilation error. Actual parameters
  1122. are coerced to the corresponding formal parameter's type.
  1123.  
  1124. ACE's parameter passing mechanism for subprograms is NOT the same as that
  1125. used for assembly code routines or C functions. In other words, the standard 
  1126. C parameter passing mechanism is not used for SUBs. This may be changed in 
  1127. the future as it makes object modules written in ACE incompatible with C or 
  1128. assembler object modules in this respect.
  1129.   
  1130. Changes made to a formal parameter have no effect upon the actual parameter 
  1131. in a simple call to an ACE subprogram, but see "Limitations" re: overwriting 
  1132. of strings/arrays during recursive calls; see also "Structures" below. 
  1133.  
  1134. The formal parameter list consists of identifiers separated by commas. Each 
  1135. identifier may also be preceded by: SHORTINT,LONGINT,ADDRESS,SINGLE or STRING 
  1136. to avoid the use of a qualifier (%&!$).
  1137.  
  1138. Actual parameters can basically be any type of expression. A whole array 
  1139. cannot be passed as a value parameter in ACE however.
  1140.  
  1141. There is an arbitrary upper limit of 40 parameters per subprogram at the
  1142. moment, which may be removed at some stage.
  1143.  
  1144. Main program variables and arrays can be accessed and modified within 
  1145. subprograms via the SHARED directive. All shared variables are passed by 
  1146. reference to a subprogram.
  1147.  
  1148. Multiple SHARED statements are allowed within a single subprogram.
  1149.  
  1150. DIM SHARED is not allowed. An array is declared to be shared in exactly the 
  1151. same way as simple variables, for example:
  1152.  
  1153.     DIM x(10)
  1154.  
  1155.     sub thing
  1156.         shared x
  1157.         .
  1158.  
  1159.                                   - page 19 -
  1160.  
  1161.         .
  1162.         end sub
  1163.  
  1164. Note that parentheses are not required after an array in the shared statement, 
  1165. nor are they legal in ACE.
  1166.  
  1167. Keep the following in mind with regard to shared variables in ACE:
  1168.  
  1169.     - Shared variables only allow access to main program
  1170.       variables from a subprogram, and do not provide a
  1171.       mechanism for changing the value of variables in 
  1172.           one subprogram from another.  
  1173.  
  1174.         - The name of a variable to be shared must correspond
  1175.       to the name of an existing (ie: already referenced/declared) 
  1176.           main program variable.
  1177.  
  1178. Although variable parameters are not explictly provided by ACE there are 
  1179. two ways to implement them: using indirection operators for simple variables 
  1180. and the ADDRESS option of DIM and STRING (see also "Structures" section).
  1181.  
  1182. Here's an example of call-by-reference parameters for simple variables:
  1183.  
  1184.     sub doub(address x)
  1185.        *!x := *!x * 2    '..n! = n!*2 [note the ":=" symbol!]
  1186.     end sub
  1187.  
  1188.     n!=22.5
  1189.     print n!
  1190.     doub(@n!)  '..pass the address of n!
  1191.     print n!
  1192.  
  1193. which passes the single-precision variable n by reference to the subprogram 
  1194. doub, where n is doubled. This will first print 22.5 and then 45.
  1195.  
  1196. For an array, the following can be done:
  1197.  
  1198.     sub test(address x)
  1199.     dim a(10) address x  
  1200.       a(3)=a(3)+12
  1201.     end sub
  1202.  
  1203.     dim n(10)
  1204.     n(3)=2
  1205.     print n(3)
  1206.     test(@n)    '..pass address of array n.
  1207.     print n(3)
  1208.  
  1209. which would print first 2 and then 14.
  1210.  
  1211. The same mechanism can be used to pass a string variable by reference (see
  1212. the STRING command's ADDRESS option).
  1213.  
  1214. These variable parameter mechanisms are most useful when used to pass data 
  1215. *between* subprograms, otherwise it is simpler to use SHARED variables.
  1216.    
  1217. The following table shows the possibilities regarding parameters and shared 
  1218. variables in ACE:
  1219.  
  1220.                                   - page 20 -
  1221.  
  1222.  
  1223. +---------------------+---------+-------------+------------------------------+
  1224. | Data Type / Object  |    Shared     | Value param | Call by Reference parameter  |
  1225. +---------------------+---------+-------------+------------------------------+
  1226. | SHORTINT VARIABLE   |    YES        | YES          |    YES - *%addr                 |
  1227. |              |             |          |                     |
  1228. | LONGINT/ADDRESS VAR |    YES     | YES          |    YES - *&addr                 |
  1229. |              |            |          |                         |
  1230. | SINGLE VARIABLE     |    YES     | YES          |    YES - *!addr                 |
  1231. |              |            |          |                         |
  1232. | STRING VARIABLE     |    YES    | YES          |    YES - STRING x ADDRESS addr  |
  1233. |              |        |          |                         |
  1234. | EXTERNAL VARIABLE   |    NO    | YES          |    YES - *%, *&, *!, STRING ..  |
  1235. |              |        |          |                     |
  1236. | ARRAY              |    YES    | NO          |    YES - DIM x ADDRESS addr     |
  1237. |              |        |          |                         |
  1238. | STRUCTURE          |    YES    | NO          |    YES - See "Structures" below |
  1239. +---------------------+---------+-------------+------------------------------+
  1240.  
  1241. Note: In the above table, "addr" is a long integer address. VARPTR or @ 
  1242. can be used to obtain this.
  1243.  
  1244.     
  1245. Structures
  1246. ----------
  1247. Structures have been included in ACE mainly because of their utility in 
  1248. gaining access to operating system functions. 
  1249.  
  1250. Structure members may be of the following type: BYTE (in structures only),
  1251. SHORTINT, LONGINT, ADDRESS, SINGLE, STRING. The latter can have an optional 
  1252. size specification. A structure may also have as a member another structure. 
  1253.  
  1254. If you want to have a pointer to a structure (or a pointer to anything else) 
  1255. as a member, simply declare it to be of type ADDRESS.
  1256.  
  1257. Allowing structures to have other structures as members makes converting 
  1258. system structures from C to ACE much easier than it otherwise would be, eg:
  1259.  
  1260.     STRUCT DateStamp
  1261.        LONGINT days
  1262.       LONGINT secs
  1263.       LONGINT ticks
  1264.       END STRUCT
  1265.  
  1266.     STRUCT myFirstStruct
  1267.       DateStamp ds
  1268.       STRING name SIZE 30
  1269.     END STRUCT
  1270.  
  1271.     DECLARE STRUCT myFirstStruct mine
  1272.     DECLARE STRUCT DateStamp *myDate
  1273.     
  1274.     .
  1275.     .
  1276.  
  1277.     myDate = @mine->ds    '..assign address of mine->ds to myDate.
  1278.     myDate->days = 23
  1279.  
  1280.  
  1281.                                   - page 21 -
  1282.  
  1283.     .
  1284.     .
  1285.  
  1286. If an array is required as a structure member, it is currently necessary 
  1287. to use STRING <ident> SIZE <bytes>. Most system structures use character
  1288. arrays (strings) anyway. As an example, if you wanted a SHORTINT array 
  1289. member with 50 elements (0..49) you could say:
  1290.  
  1291.     STRUCT mySecondStruct
  1292.       STRING myArray SIZE 100    '..reserve space for the array
  1293.       .
  1294.       .
  1295.     END STRUCT
  1296.     
  1297.     DECLARE STRUCT mySecondStruct aStruct
  1298.  
  1299.     DIM N%(100) ADDRESS @aStruct->myArray
  1300.  
  1301. You can of course use SIZEOF to determine the number of bytes ACE would
  1302. set aside for a particular array. A two line program would accomplish
  1303. this:
  1304.  
  1305.     DIM a_short_array%(49)
  1306.     PRINT SIZEOF(a_short_array%)
  1307.  
  1308. The value thus derived can then be used when declaring a structure such
  1309. as the one shown above.
  1310.  
  1311. Note that in the case of the array and structure members above, it is 
  1312. necessary to take the address of the member and assign it to a normal
  1313. array or structure (pointer to structure - see below) variable. 
  1314.  
  1315. When declaring a structure, the only difference between the following two
  1316. forms:
  1317.  
  1318.         DECLARE STRUCT mystructtype mystruct
  1319.     and
  1320.         DECLARE STRUCT mystructtype *mystruct
  1321.  
  1322. is that for the former, an appropriate data object is created (on a long
  1323. word boundary), but not for the latter.
  1324.  
  1325. In both cases, mystruct contains the start address of a structure of type 
  1326. mystructtype. In the second case, the address is NULL until assigned a value 
  1327. (eg: with ALLOC). In both cases, the address can be reassigned at will, 
  1328. although this should only really be done for structure pointers (the second
  1329. form).
  1330.  
  1331. Since both forms of structure declaration result in an address being stored
  1332. (in mystruct in the example), the dereferencing operator is always "->".
  1333.  
  1334.     examples:
  1335.     --------
  1336.  
  1337.     PRINT mystruct          -  prints the start address of the structure.
  1338.  
  1339.     PRINT mystruct->mins -     prints the value of a member called mins.
  1340.   
  1341.  
  1342.                                   - page 22 -
  1343.  
  1344. The SIZEOF function can be used to determine the size of a structure type
  1345. if allocating memory for a structure (see prgs/misc/linkedlist.b).
  1346.  
  1347. ACE structures are stand-alone data objects, and cannot be elements in an 
  1348. array, although structure *addresses* _can_ be. For an example of the 
  1349. latter, see prgs/misc/array_of_structs.b.
  1350.  
  1351. An ACE structure can be SHARED to allow its member's values to be modified, 
  1352. or a structure's address can be passed to a subprogram, eg:
  1353.  
  1354.     struct my
  1355.        longint one
  1356.        longint two
  1357.     end struct
  1358.     
  1359.     sub test(addr&)
  1360.     declare struct my *second
  1361.        second=addr&
  1362.        second->one = second->one * 2
  1363.     end sub
  1364.  
  1365.     '..main
  1366.     declare struct my first
  1367.     first->one=12
  1368.     print first->one
  1369.     test(first)
  1370.     print first->one
  1371.  
  1372. which will print 12 followed by 24.
  1373.  
  1374. The following code allocates enough memory to hold a structure of type "my", 
  1375. gives values to the structure's 2 members, and changes the address held by 
  1376. the structure variable "third" to the start of the newly allocated memory 
  1377. area:
  1378.  
  1379.     declare struct my *third
  1380.  
  1381.     sub create(ADDRESS a_struct)
  1382.     declare struct my *temp
  1383.       temp = ALLOC(sizeof(my))
  1384.       temp->one = 16
  1385.       temp->two = 10
  1386.       *&a_struct := temp    '..change structure variable's value
  1387.     end sub
  1388.  
  1389.     '..main
  1390.     create(@third)
  1391.     .
  1392.     .
  1393.  
  1394. Finally, it is not currently possible to use INPUT, (LINE) INPUT# or READ 
  1395. in conjunction with structures.
  1396.  
  1397.     
  1398. Shared library function calls
  1399. -----------------------------
  1400. ACE provides access to shared libraries in the same way as AmigaBASIC does
  1401. with the exception that you MUST declare a function in order to use it. 
  1402.  
  1403.                                   - page 23 -
  1404.  
  1405.  
  1406. Also, the library in question must either be in LIBS: or in ROM.
  1407.  
  1408. As of version 2.0, ACE and AmigaBASIC are otherwise pretty much the same. 
  1409. The ACE commands also retain their earlier syntax for backward compatibility 
  1410. and convenience.
  1411.  
  1412. The commands are as follows:
  1413.  
  1414. LIBRARY <libname>    
  1415.  
  1416.     - Where <libname> is the name of a shared library with or 
  1417.       without quotes (eg: "graphics", "graphics.library", graphics).
  1418.  
  1419.     - A ".library" or ".bmap" suffix is allowed but optional.
  1420.  
  1421.            - The LIBRARY command opens the shared library and provides
  1422.       a copy of its base address for use internally by function 
  1423.       calls.
  1424.  
  1425.     - If a library can't be opened at run-time, the program 
  1426.       will abort.
  1427.  
  1428.  
  1429. LIBRARY CLOSE [<libname>]
  1430.  
  1431.     - Closes the specified shared library or all open libraries
  1432.       if no library name is given.
  1433.  
  1434.     - Closing a library more than once will cause no harm.
  1435.  
  1436.  
  1437. Notes about standard libraries used by ACE:
  1438.  
  1439.     - There are currently six standard libraries which are often opened 
  1440.       by ACE routines during a program run. These are: dos, intuition,
  1441.       graphics, mathffp, mathtrans and translator libraries.
  1442.  
  1443.     - If one of these six is opened by the LIBRARY command it will 
  1444.       be opened at the start of the program *and* closed at the end. 
  1445.       Any other library will be opened and closed at the points in 
  1446.       the program specified by you.
  1447.  
  1448.     - You don't actually have to close any of the six libraries 
  1449.       mentioned above, but it won't hurt.
  1450.  
  1451.     - Moreover, you never have to open or close the dos.library
  1452.       since ACE opens it for EVERY program.
  1453.  
  1454.  
  1455. DECLARE FUNCTION <funcname>[%&!#$][(param-list)] LIBRARY [<libname>]
  1456.         
  1457.     - Where <funcname> is the case sensitive name of a function in a
  1458.       shared library.
  1459.  
  1460.     - <funcname> may have a trailing character (&%#!$) to indicate type,
  1461.       otherwise default data type rules apply for the function's return 
  1462.       value. This character is optional when CALLing the function.
  1463.  
  1464.                                   - page 24 -
  1465.  
  1466.  
  1467.     - The optional parameter-list is for documentation purposes only
  1468.       and is otherwise ignored.
  1469.  
  1470.     - If <libname> (same as for LIBRARY and LIBRARY CLOSE) is specified, 
  1471.       ACE only looks in the bmap file for that library, otherwise ACE
  1472.       looks for the function in the bmap files for all open libraries 
  1473.       and all the standard libraries known to the compiler. Needless 
  1474.       to say that specifying <libname> results in faster bmap file
  1475.       entry lookups. This option is not given by AmigaBASIC however.
  1476.  
  1477.     - Example: DECLARE FUNCTION SetSoftStyle LIBRARY
  1478.  
  1479.  
  1480. [CALL] <funcname>[(parameter-list)]
  1481.  
  1482.     - Transfers control to the function <funcname>, loading the
  1483.       appropriate registers before doing so, according to the
  1484.       information about that function in the library's bmap file. 
  1485.  
  1486.      - The return value of a function can be accessed by calling
  1487.       a function as part of an expression, eg: addr& = AllocMem(100,2).
  1488.  
  1489. Function declarations are GLOBAL. They are are NOT optional in ACE.
  1490.  
  1491. ** PLEASE NOTE ***
  1492. No type checking of parameters is performed, so expect weirdness if you pass
  1493. values of the wrong type to a shared library function. ACE _does_ however now 
  1494. automatically promote all short integers to long integers by sign-extension.
  1495.  
  1496. When passing strings as parameters it is not necessary to add a CHR$(0)
  1497. to the end of a string since ACE strings are already NULL terminated. 
  1498.  
  1499. Either VARPTR or SADD can safely be used to find the address of a string 
  1500. variable or constant. Actually, the use of SADD or VARPTR for strings
  1501. passed to library functions is optional, but it's probably a good idea to 
  1502. use one or the other all the time, for consistency's sake. These comments 
  1503. also apply to calling machine code routines and external functions.
  1504.   
  1505. It is up to YOU to open and close libraries correctly. ACE doesn't keep
  1506. track of this, and will try to jump to a library function so long as 
  1507. it finds a reference to it in a bmap file even if the library hasn't 
  1508. been opened! As mentioned above, it is not necessary to open and close 
  1509. dos.library because _every_ ACE program does this.
  1510.  
  1511. ACE expects the bmap file for a library to be in the directory ACEbmaps:
  1512. (see "Installation").
  1513.  
  1514. Given Commodore's liquidation this year and the resultant confusion over 
  1515. who's now in charge of all this kind of stuff, I have no idea when or if the 
  1516. .bmaps will be provided with the ACE archive. However, this doesn't really
  1517. matter so long as you have the .FD files. Read on...
  1518.  
  1519. As of version 2.0, I have provided a program (FD2BMAP) which is functionally 
  1520. equivalent to ConvertFD (since this may NOT be freely redistributed) so that 
  1521. bmap files for new libraries can be created. The program FD2BMAP can be found 
  1522. in the ACE:utils/fd2bmap directory and was written in ACE by Harald Schneider, 
  1523. with some modifications from me.
  1524.  
  1525.                                   - page 25 -
  1526.  
  1527.  
  1528. The 1.3 FD files can be found in the BasicDemos drawer on the Extras disk. 
  1529.  
  1530. The FD files for Release 2.x/3.x are available from Commodore (who?) for 
  1531. about $30 (you get six disks of developer goodies: ask for the Native 
  1532. Developer Kit).
  1533.  
  1534. The FD files can also be found on Fred Fish's CD-ROMs and on the InterNet
  1535. FTP site: ftp.rz.uni-wuerzburg.de in /pub/amiga/frozenfish/bbs/cbm. Note
  1536. that FDs obtained from these sources are not freely redistributable and
  1537. must be obtained on an individual basis, presumably to prevent modification
  1538. when being passed through many hands.
  1539.  
  1540. AmigaBASIC cannot handle functions which use address register a5. This is 
  1541. not true for ACE. Neither ACE nor AmigaBASIC allow the use of functions which
  1542. use register a6 however.
  1543.  
  1544. See the programs in prgs/Library for examples of how to use shared 
  1545. library functions in ACE.
  1546.  
  1547.   
  1548. Machine code calls
  1549. ------------------
  1550. ACE supports AmigaBASIC's mechanism for calling machine code routines and
  1551. the passing of parameters to such routines. AmigaBASIC's stack conventions 
  1552. are also followed (ie: C style parameter passing).
  1553.  
  1554. The syntax for calling such a routine is:
  1555.  
  1556.     CALL long-integer-variable-name[(parameter-list)]
  1557.  
  1558. Note that CALL is NOT optional. Also, the variable containing the address 
  1559. of the routine *must* be a long integer (LONGINT or ADDRESS) in ACE.
  1560.  
  1561. For example, 
  1562.  
  1563.     CALL caps&(length&,addr&)
  1564.  
  1565. will set up the stack like this:
  1566.     
  1567.     8(sp) = addr&
  1568.     4(sp) = length&
  1569.     0(sp) = return address
  1570.  
  1571. on entry to the machine code subroutine caps&.
  1572.  
  1573. On exit from a routine, ACE cleans up the stack by POPping all parameters.
  1574.  
  1575. You can use a short integer array, a string or an allocated area of memory
  1576. (eg. with ACE's ALLOC function) to poke the bytes of a machine code routine 
  1577. into. I prefer the latter method.
  1578.  
  1579. Note that because ACE treats ASCII 0 as the end-of-string character, don't 
  1580. use the string-building method, eg:
  1581.  
  1582.     z$=""
  1583.     for i=1 to N
  1584.          read b
  1585.  
  1586.                                   - page 26 -
  1587.  
  1588.       z$=z$+chr$(b)
  1589.         next
  1590.  
  1591. since if b=0, chr$(b) will be the NULL string. If you want to use a string,
  1592. do the following:
  1593.  
  1594.     z$=""    '..or STRING z$ SIZE 100 (if there are 100 bytes of MC).
  1595.     addr&=sadd(z$)
  1596.     for i&=0 to N-1
  1597.       read b%
  1598.       poke addr&+i&,b%
  1599.     next
  1600.     call addr&
  1601.  
  1602. The latter is okay, so long as you don't allocate other strings with odd 
  1603. sizes. But if you want to be sure that you have an area of memory which 
  1604. is long-word aligned, use ALLOC (or AllocMem), eg:
  1605.  
  1606.     addr&=Alloc(100)    '..100 bytes of ANY memory
  1607.     for i&=0 to N-1
  1608.       read b%
  1609.       poke addr&+i&,b%
  1610.     next
  1611.     CALL addr&
  1612.  
  1613. The above examples assume the presence of appropriate DATA statements. See 
  1614. the prgs/MC directory for examples.
  1615.  
  1616. ACE also supports primitive inline assembly code inclusion. See ref.doc
  1617. under ASSEM..END ASSEM for details.
  1618.  
  1619.  
  1620. External references
  1621. -------------------
  1622. Reference can be made to a variable or function in another file which is
  1623. resolved at link time. You may for instance, have written a function in C
  1624. or assembler. It is possible to pass parameters to, call and obtain return
  1625. values (as with ACE SUBs) from such a function in ACE after declaring an 
  1626. external reference to the function with the EXTERNAL FUNCTION or DECLARE
  1627. FUNCTION ... EXTERNAL directive (see command and function reference for 
  1628. syntax).
  1629.  
  1630. When passing parameters, standard C parameter passing conventions
  1631. are used. Although some C compilers seem to pass all parameters as
  1632. 4 bytes per parameter on the stack, ACE allows 2 (short words) or 4 
  1633. byte parameters. Be aware of this! See prgs/ExternFunc for examples.
  1634.  
  1635. External variables can be assigned values like normal variables, eg:
  1636.  
  1637.         external RangeSeed&
  1638.         RangeSeed=5276&
  1639.  
  1640. Instead of the "&" qualifier, the following is also legal:
  1641.  
  1642.         external longint RangeSeed
  1643.  
  1644. External function return values may be of any type as may external variables.
  1645.  
  1646.  
  1647.                                   - page 27 -
  1648.  
  1649. Note however that externally referenced string variables are assumed to be 
  1650. arrays of characters ala C, eg.
  1651.  
  1652.         char my_buffer[80];
  1653. or
  1654.         char my_string[] = "Hello World!";
  1655.  
  1656. but _not_ a character pointer, eg:
  1657.  
  1658.         char *a_char_pointer = "Hello World!";
  1659.             
  1660. Use a C function to return a character pointer, and externally reference it
  1661. from your ACE program.
  1662.  
  1663. All external reference identifiers have an underscore prefixed by ACE but
  1664. this is optional when declaring or using an external reference. C compilers 
  1665. always seem to prefix referenceable symbols with an underscore, so ACE does 
  1666. too.
  1667.  
  1668. Note that the names of external references (all except external SUBs -
  1669. see below) *are* case sensitive.
  1670.  
  1671. Also, the bas script can take as a third argument the name of the object 
  1672. file produced from the original C or assembly source (ie: .o or .lib file) 
  1673. which contains the external function or variable to be linked with your
  1674. ACE program. AIDE has facilities which allow for the linking of multiple
  1675. object modules.
  1676.  
  1677. You can't easily call ACE SUBs from C or assembler because ACE SUBs don't 
  1678. use C parameter passing conventions and ACE code relies heavily upon linking
  1679. code from run-time libraries (db.lib and startup.lib).
  1680.  
  1681.  
  1682. Creating & using ACE subprogram modules
  1683. ---------------------------------------
  1684. It is now possible to create libraries of ACE subprograms and so to have
  1685. multi-file ACE projects. For example in one file you can have:
  1686.  
  1687.     SUB lines(n) EXTERNAL
  1688.       FOR i=1 to n
  1689.         LINE (RND*640,RND*200)-(RND*640,RND*200)
  1690.       NEXT
  1691.     END SUB
  1692.  
  1693. and in another file:
  1694.  
  1695.     '..main
  1696.     DECLARE SUB lines(n) EXTERNAL
  1697.     LIBRARY "graphics.library"
  1698.     WINDOW 1,,(0,0)-(640,200)
  1699.     lines(500)
  1700.     WINDOW CLOSE 1
  1701.     END
  1702.  
  1703. If the latter file is called say, main.b and the former is called lines.b
  1704. then the following sequence of shell commands will give you an executable
  1705. called main:
  1706.  
  1707.  
  1708.                                   - page 28 -
  1709.  
  1710.     ace -Om lines        { The -m switch is the key here }
  1711.     a68k lines.s
  1712.     bas -O main lines.o
  1713.  
  1714. The first two commands can be replaced by:
  1715.  
  1716.     module lines
  1717.  
  1718. which is a shell script in the bin directory. The effect of the last of 
  1719. the 3 commands shown above can also be achieved via the Linker menu in 
  1720. AIDE, while the Compiler menu "Create Linkable Module" option is the 
  1721. equivalent of the first two.
  1722.  
  1723. There are a few things to be kept in mind when using ACE modules:
  1724.     
  1725.     1. Only subprograms - not subroutines (ie. via GOTO/GOSUB) - in 
  1726.     such modules can be called from other modules.
  1727.  
  1728.     2. The main module *MUST* open all standard libraries required
  1729.     by the other ACE modules linked to it. If in doubt add the 
  1730.     following lines of code at the top of your main program:
  1731.  
  1732.             LIBRARY mathffp
  1733.             LIBRARY mathtrans
  1734.             LIBRARY graphics
  1735.             LIBRARY intuition
  1736.             LIBRARY translator    '..only if TRANSLATE$ used
  1737.  
  1738.     If your code works as a single-module program but you invoke 
  1739.     the GURU or your program just doesn't work anymore when part 
  1740.     of it is placed into a linkable module, the above should fix it.
  1741.  
  1742.     3. The "m" switch creates an assembly source module containing 
  1743.     bare code with no calls to the startup functions normally invoked
  1744.     by an ACE program. Because of this, you need to keep the following
  1745.     in mind:
  1746.  
  1747.     - Command-line arguments must either be handled in the main
  1748.       program module or ARGCOUNT or ARG$ must be used one or more 
  1749.       times in the main module if they are going to be used in a 
  1750.       module produced with ACE's "m" switch. A line of code in 
  1751.       the main module such as:
  1752.  
  1753.         n = ARGCOUNT
  1754.  
  1755.       will suffice.
  1756.  
  1757.     - Likewise, if ALLOC is used in a module, it must also be used 
  1758.       at least once in the main program (eg. x=ALLOC(0) - no bytes
  1759.       will be allocated).     
  1760.  
  1761. In both cases, it is a matter of letting the compiler know that these
  1762. features are required by the final executable program which the above
  1763. actions will do.
  1764.  
  1765.     - In order to use DATA/READ within a module, make sure you issue
  1766.       a RESTORE command (in a subprogram) before the _first_ READ is 
  1767.       executed. This RESTORE command *must* be in a subprogram.
  1768.  
  1769.                                   - page 29 -
  1770.  
  1771.  
  1772.       For example, in the calling module:
  1773.  
  1774.         library mathffp
  1775.         declare sub data_test external
  1776.         data_test
  1777.  
  1778.       and in the library module:
  1779.  
  1780.         sub data_test external
  1781.             restore
  1782.             read x
  1783.             print x
  1784.             data 1.345    '..DATA lines _can_ be outside of SUBs
  1785.         end sub
  1786.  
  1787.     - ON TIMER normally has special startup code associated with it.
  1788.       Since there _is_ no startup code in modules, you will have to
  1789.       include the following lines of code such that they will be 
  1790.       executed before the ON TIMER code:
  1791.  
  1792.         external function ontimerstart
  1793.         ontimerstart
  1794.  
  1795.       For example, in the calling module:
  1796.  
  1797.           library mathffp
  1798.           declare sub timer_test external
  1799.           timer_test
  1800.  
  1801.       and in the library module:
  1802.  
  1803.           sub timer_test external
  1804.         SHORTINT count
  1805.           external function ontimerstart    '..can be outside SUB
  1806.           ontimerstart
  1807.             on timer(1) gosub do_beep
  1808.             timer on
  1809.             while -1
  1810.                 if count=5 then exit sub
  1811.             wend  
  1812.           do_beep:
  1813.               ++count
  1814.               beep
  1815.               return
  1816.         end sub
  1817.  
  1818. In addition, while subprograms can be treated as functions when in modules,
  1819. because there is no startup code, SUBs in a module are allocated no space
  1820. for return value storage. This means that function return values must be
  1821. passed by some method other than via the stack frame. In this case, ACE
  1822. uses the 680x0 register d0. Since d0 can be overwritten at any time, the
  1823. final thing a subprogram (in a module) should do is to assign the return 
  1824. value for the subprogram. C forces you to do this anyway, it's just 
  1825. that ACE normally gives you more flexibility than C. For example, the 
  1826. following:
  1827.  
  1828.     SUB even(n) EXTERNAL
  1829.  
  1830.                                   - page 30 -
  1831.  
  1832.       m = n MOD 2
  1833.       IF m=0 THEN
  1834.         even = -1
  1835.       ELSE
  1836.         even = 0
  1837.       END IF 
  1838.     END SUB
  1839.  
  1840. is acceptable since the final action of the subprogram is to assign itself
  1841. a return value. On the other hand, the following will cause d0 to be 
  1842. overwritten before the subprogram can return its value to the caller:
  1843.  
  1844.     SUB even(n) EXTERNAL
  1845.       m = n MOD 2
  1846.       IF m=0 THEN
  1847.         even = -1
  1848.       ELSE
  1849.         even = 0
  1850.       END IF 
  1851.         PRINT n;"mod 2 is";m    ' trashes d0!!
  1852.     END SUB
  1853.  
  1854. If need be of course, you can simply use a temporary local variable to
  1855. hold the final return value to be assigned later.
  1856.  
  1857. Note that the d0 convention ONLY applies when the "m" compiler switch is
  1858. used and that it applies to all subprograms in a module. However, even if
  1859. a SUB is declared to be external, the d0 parameter passing convention will
  1860. not be used unless either: (i) the "m" switch is used for the module in 
  1861. which the SUB is defined, or (ii) a SUB is used after being externally
  1862. referenced via DECLARE SUB ... EXTERNAL.
  1863.  
  1864. Instead of an external SUB, it is legal to have an external DEF FN. The
  1865. forward declaration is still the same as for a SUB. The definition for
  1866. the "even" function (in a module) looks like this:
  1867.  
  1868.     DEF even(n) EXTERNAL = -(n MOD 2)
  1869.  
  1870. Remember also that only variables which are local to SUBs and subprogram 
  1871. parameters may be used in a module. Global variables are not provided for 
  1872. correctly when declared in a module produced with the "m" switch, again 
  1873. because of the lack of startup code.
  1874.  
  1875. Finally, be careful to match up the return and parameter types for an 
  1876. externally defined subprogram and its forward (external) declaration.
  1877.  
  1878.  
  1879. Windows
  1880. -------
  1881. You can open up to nine user-defined windows per program. See the command 
  1882. and function reference for the syntax of the WINDOW statement.
  1883.  
  1884. All user-defined windows are now (as of ACE v2.0) Intuition windows with 
  1885. each characteristic being configurable via the "type" parameter as per 
  1886. AmigaBASIC (see ref.doc).
  1887.  
  1888. Windows can be opened on the Workbench screen or on a user-defined screen.
  1889.  
  1890.  
  1891.                                   - page 31 -
  1892.  
  1893. The zeroth window (the shell/CLI, if the program was CLI launched) is now
  1894. the only instance of a DOS console window in ACE.
  1895.  
  1896. The WINDOW function takes a single parameter and returns information about
  1897. the current output window. See ref.doc for details.
  1898.  
  1899. Note that for user-defined windows, close-gadget clicks must be handled by 
  1900. the use of ON WINDOW event trapping or via the "w" compiler switch (or the
  1901. OPTION w+ command).
  1902.  
  1903. Please read the next section for more information about how windows relate
  1904. to screens in ACE.
  1905.  
  1906.   
  1907. Screens
  1908. -------
  1909. A single program can have open nine screens at once (memory permitting).
  1910.  
  1911. By default, when a screen is opened, a (BORDERLESS+BACKDROP) window
  1912. the same size as the screen is also opened. Subsequent output is directed 
  1913. to and input received from this window until the screen is closed (unless 
  1914. other windows are defined for the screen). Note that this feature is not 
  1915. found in AmigaBASIC. Note also that this default window is *not* counted
  1916. as having a window-id of 0. That privilege is reserved for the shell window
  1917. if the program was shell-launched. Read on...
  1918.  
  1919. The main use for such a default window is to provide a simple graphics
  1920. output "slate" for quick-and-dirty programs. The borderless+backdrop
  1921. characteristic prevents user-defined windows which may later be opened 
  1922. onto the screen from accidentally being depth arranged behind an invisible
  1923. window where they would stay for the remainder of that screen's life. With
  1924. a backdrop window this cannot happen since it will _always_ be the rear-most
  1925. window for a screen.
  1926.  
  1927. Text and graphics positions will be different on a screen's default window 
  1928. than for user-defined windows. For example, text in the first row will be 
  1929. partially off the top of the screen, so LOCATE may need to be used to adjust 
  1930. this. In short, I recommend that default windows now ONLY be used for rough 
  1931. output. If you still want a borderless window, use the  WINDOW command and 
  1932. ensure that the window-type has 32 as a component.
  1933.  
  1934. Avoid mixing the use of default and user-defined windows. Except for the
  1935. simple case in which you use nothing but screens and their default windows
  1936. you should consider your own windows to be the primary output destination 
  1937. for graphics and text.
  1938.  
  1939. Windows with depth gadgets cannot be sent behind the default window, but 
  1940. one screen can be sent to the back of other screens. It can also be moved 
  1941. vertically (and possibly horizontally). SCREEN BACK|FORWARD can be used to 
  1942. shuffle screens under program control.
  1943.  
  1944. When a screen is closed, ACE makes the screen with the next highest id 
  1945. the current one, so it is advisable to open and close screens in ascending 
  1946. and descending order.
  1947.  
  1948. A special SCREEN function exists in ACE which returns pointers to various
  1949. Intuition structures (window,screen,rastport,viewport,bitmap) and x,y font
  1950. sizes. This is detailed in the command and function reference (ref.doc) as 
  1951.  
  1952.                                   - page 32 -
  1953.  
  1954. are the following commands: SCREEN, SCREEN CLOSE, PALETTE and PRINTS. The 
  1955. latter is now redundant since all commands and functions can - as of ACE v2.0 
  1956. - be used transparently for screens, user-defined windows and the shell/CLI.
  1957.  
  1958.  
  1959. Gadgets
  1960. -------
  1961. ACE supports the Amiga's three standard gadget types: boolean, proportional 
  1962. (vertical and horizontal), and string (including long integer). 
  1963.  
  1964. Since one of my aims is to support all Amigas running everything from Wb 1.3 
  1965. to Wb 3.0, I have chosen to stick with simple Intuition gadgets for now.
  1966.  
  1967. Even so, ACE now supports the 3D bevel-box look of GadTools gadgets found
  1968. under Wb 2.x/3.0. Moreover, a BEVELBOX command allows the programmer to
  1969. create such boxes at will.
  1970.  
  1971. A future revision may support other gadget types, such as radio buttons, 
  1972. check boxes, list boxes etc.
  1973.  
  1974. Memory permitting, up to 255 gadgets can be created during a single program 
  1975. run.
  1976.  
  1977. The GADGET command creates a gadget with specific features while GADGET CLOSE 
  1978. removes the gadget from the window. Once created, a gadget can be enabled or
  1979. disabled, indeed it can be disabled upon creation if so desired. The GADGET
  1980. MOD command modifies the state of a slider (knob size and position).
  1981.  
  1982. Having created a gadget or gadgets, you must then decide how to receive and
  1983. handle information from them. ACE provides four methods: standard event
  1984. trapping (ON GADGET), polling (via the GADGET function), WAITing for a
  1985. specific gadget or WAITing for any gadget.
  1986.  
  1987. Where it is possible to make your programs modal (ie. focussed upon a single
  1988. event or event type) you can use the GADGET WAIT command.
  1989.  
  1990. The following commands set up a window with two boolean gadgets and a close 
  1991. gadget. The latter is set up by Intuition with the WINDOW command.
  1992.  
  1993. The program traps WINDOW and GADGET events. The comments should help you to
  1994. understand the code.
  1995.  
  1996. CONST having_fun = -1&
  1997.  
  1998. WINDOW 1,"Gadgets",(0,0)-(640,200),8
  1999.  
  2000. GADGET 1,ON,"Hit Me",(3,3)-(75,20),BUTTON,1
  2001. GADGET 2,OFF,"Quit",(100,150)-(200,175),BUTTON,2
  2002.  
  2003. ON GADGET GOSUB gadget_handler
  2004. GADGET ON
  2005.  
  2006. ON WINDOW GOTO quit
  2007. WINDOW ON
  2008.  
  2009. '..main loop (actually does nothing, but is necessary for event trapping)
  2010. WHILE having_fun
  2011.   '..have a nap while nothing's happening 
  2012.  
  2013.                                   - page 33 -
  2014.  
  2015.   '..(don't hog the machine by busy waiting) 
  2016.   SLEEP        
  2017. WEND
  2018.  
  2019. gadget_handler:
  2020.   '..find out which gadget was selected
  2021.   gad = GADGET(1)
  2022.   LOCATE 12,40:PRINT "<<";gad;">>" 
  2023.   if gad = 2 then quit    
  2024. RETURN
  2025.  
  2026. quit:
  2027.   GADGET CLOSE 2
  2028.   GADGET CLOSE 1
  2029.  
  2030.   WINDOW CLOSE 1
  2031. END
  2032.  
  2033. Alternatively, you could poll for a gadget to the exclusion of other events:
  2034.  
  2035. .
  2036. .
  2037. '..await a gadget selection
  2038. REPEAT
  2039.   WHILE NOT GADGET(0)
  2040.     SLEEP  '..be a little nice to other tasks
  2041.   WEND
  2042.   
  2043.   '..which one?
  2044.   gad = GADGET(1)
  2045.   LOCATE 12,40
  2046.   PRINT "<<";gad;">>" 
  2047. UNTIL gad=2
  2048. .
  2049. .
  2050.  
  2051. Finally, you can wait for a gadget:
  2052.  
  2053. .
  2054. .
  2055. GADGET WAIT 2      '.."GADGET WAIT 0" waits for ANY gadget! -> BEST method!
  2056. .
  2057. .
  2058.  
  2059. See the program prgs/GUI/ACEgadgets.b for an example of gadget programming
  2060. in ACE.
  2061.  
  2062. For boolean gadgets you can - if you need to - get information about the 
  2063. width and height of the gadget's text font by calling SCREEN(5) and 
  2064. SCREEN(6). If you need more precise width information, use the graphics 
  2065. library TextLength or TextExtent (v36) function.
  2066.  
  2067. String and LongInt gadgets now have associated with them a 1K buffer.
  2068.  
  2069. For more details about the GADGET commands and function, see ref.doc.
  2070.  
  2071.  
  2072. Menus
  2073.  
  2074.                                   - page 34 -
  2075.  
  2076. -----
  2077. ACE supports menus ala AmigaBASIC, with two additions: menu item keyboard
  2078. equivalents and a MENU WAIT command. The latter puts the program to sleep 
  2079. until a menu event occurs. The former is specified by an optional parameter 
  2080. to the MENU command, for example:
  2081.  
  2082.     MENU 1,5,1,"Quit","Q"
  2083.  
  2084. defines menu item number 5 in menu number 1 to be the 'Quit' option and 
  2085. sets up a command-key sequence (Amiga-Q) for that item. The third parameter
  2086. enables the menu item as per AmigaBASIC.
  2087.  
  2088. Note that although ACE adjusts menu text for font size and type as set
  2089. via preferences, some fonts may require you to pad your menu title/item 
  2090. names with blanks when using command keys to avoid overlaps, so it is a
  2091. good idea to add a couple of spaces to the end of a menu item string.
  2092.  
  2093. For an example of menu programming with ACE see prgs/ifs.b. For a better
  2094. example, see the source code for AIDE. Over time I will modify some of 
  2095. the other example programs in the archive so that they are menu-driven.
  2096.  
  2097. Note that in ACE, MENU CLEAR replaces MENU RESET.
  2098.  
  2099. See ref.doc for more details about the MENU commands and function.
  2100.  
  2101.  
  2102. Requesters
  2103. ----------
  2104. As of version 2.0, ACE supports 3 standard requesters:
  2105.  
  2106.     - System requester
  2107.     - File requester
  2108.     - Input requesters (STRING and LONGINT)
  2109.  
  2110. Visual Basic for Windows has had an influence upon me and led me to add these
  2111. to ACE since I have now come to expect them. You can get the most commonly 
  2112. needed requesters with a single line of ACE code!
  2113.  
  2114. If you are running Wb 2.x and above, ACE generates an ASL file requester.
  2115.  
  2116. For Wb 1.3 an ARP file requester is invoked for two simple reasons:
  2117.  
  2118.     - It is quite acceptable.
  2119.     - The arp.library is common on Wb 1.3 systems.
  2120.  
  2121. See MSGBOX, FILEBOX, INPUTBOX and INPUTBOX$ in ref.doc for more.
  2122.  
  2123.     
  2124. Turtle Graphics
  2125. ---------------
  2126. You may be wondering one or more of the following:
  2127.  
  2128.     - what the heck is Turtle Graphics?
  2129.     - isn't that for kids?
  2130.     - why did he include THAT?
  2131.  
  2132. To answer the first question: Turtle Graphics (TG) originated as a subset of 
  2133. the language LOGO invented by Seymour Papert et al at MIT. LOGO was originally 
  2134.  
  2135.                                   - page 35 -
  2136.  
  2137. intended as a language for learning. Children are able to write simple programs
  2138. to draw shapes on the computer's screen or move a Turtle - a dome-shaped robot 
  2139. - on a sheet of paper on the floor, learning about geometry "by doing" and
  2140. having fun to boot. 
  2141.  
  2142. LOGO also has many Lisp-like qualities and so can be used as a language for 
  2143. AI work, although to my knowledge, it's not.
  2144.  
  2145. But I digress. Apart from the fun kids can have with TG, it's actually 
  2146. possible to construct quite complex shapes with it. Combined with recursion,
  2147. TG is a powerful tool. It is particularly useful in plotting many fractal
  2148. shapes (see snowflake.b, dragon.b).
  2149.  
  2150. Since the first LOGO, there have been many manifestations of TG. Turbo Pascal 
  2151. for the PC and the Mac have both had TG.
  2152.  
  2153. A few years ago, I  wrote a pure TG subset of LOGO which used the same syntax 
  2154. as the original language and allowed recursive procedures. I've also written 
  2155. TG functions in C. Both of these have been useful to me and I've often wished 
  2156. that BASIC came with TG built-in. Well, now one dialect does!
  2157.  
  2158. For some examples of the use of Turtle Graphics in ACE, see the following
  2159. programs:
  2160.  
  2161.     - tree.b
  2162.     - flower.b
  2163.     - boxit.b
  2164.     - torus.b
  2165.     - dragon.b
  2166.     - snowflake.b
  2167.     - bst.b
  2168.  
  2169. The above discussion should have answered the second question. As for 
  2170. the third, the answer is: because I wanted to!! :^)
  2171.  
  2172. Okay, enough philosophy. Here's the ACE stuff:
  2173.  
  2174. BACK n        - move turtle back by n.
  2175. FORWARD n    - move turtle forward by n.
  2176. HEADING     - return turtle's current heading in degrees (0..359).
  2177. HOME        - move turtle back to its home position.
  2178. PENDOWN        - put turtle's pen down. 
  2179. PENUP        - lift turtle's pen up.
  2180. SETHEADING degs - change turtle's heading to degs.
  2181. SETXY x,y    - change turtle's current x,y location.
  2182. TURN degs    - rotate turtle by degs.
  2183. TURNLEFT degs    - turn turtle left by degs.
  2184. TURNRIGHT degs  - turn turtle right by degs.
  2185. XCOR        - return turtle's current x-coordinate.
  2186. YCOR        - return turtle's current y-coordinate.
  2187.  
  2188. where:
  2189.     - n is pixels
  2190.     - degs is a signed short integer representing degrees with
  2191.       the turtle starting at a 270 degree orientation -- pointing up.
  2192.     - home is the turtle's x,y start location (0,0).
  2193.  
  2194. Note that the X:Y ratio can be modified thus:
  2195.  
  2196.                                   - page 36 -
  2197.  
  2198.  
  2199.     EXTERNAL SINGLE tg_xy_ratio
  2200.     tg_xy_ratio = 1.125    
  2201.  
  2202. but this should not be necessary (from v2.19) since ACE determines the
  2203. correct aspect ratio for each user-defined screen when it is opened. A 
  2204. hi-res, non-interlaced Workbench screen is assumed at startup however. 
  2205. The correct values for tg_xy_ratio are shown below:
  2206.  
  2207.     Screen mode            Aspect ratio    
  2208.     -----------            ------------
  2209.     Lo-res, non-interlaced        0.9375
  2210.     Hi-res, non-interlaced        1.875
  2211.     Lo-res, interlaced        0.46875
  2212.     Hi-res, interlaced        0.9375
  2213.     Hold and Modify (HAM)        0.9375
  2214.     Extra-Halfbrite            0.9375
  2215.  
  2216. Most LOGO environments use a coordinate system where 0,0 is at the center of
  2217. the screen and positions to the left and down of this origin are negative 
  2218. while those up and to the right are positive. ACE's TG system however, uses 
  2219. the Amiga's normal graphics coordinate system with 0,0 at the top left of 
  2220. the screen/window so as to maintain consistency with ACE's normal graphics 
  2221. commands and functions (eg: POINT, PSET, LINE, PAINT, CIRCLE, AREAFILL).
  2222.   
  2223. If a negative value is specified for the turnleft or turnright commands,
  2224. the turtle will be rotated in the opposite direction to that indicated by
  2225. the the command name. Note that there is also a TURN command.
  2226.  
  2227. When using ACE's TG system, it's best to think of an imaginary turtle (in LOGO
  2228. it's usually a small triangle on the screen) which rotates and moves according
  2229. to your whim. The turtle can either have its pen lowered or raised - and will
  2230. therefore draw or not - which is useful when you need to move in a relative 
  2231. fashion from one location to another without drawing anything.      
  2232.  
  2233. SetXY is like the graphics library Move() command and may need to be preceded 
  2234. by PENUP unless you want to draw a line as the turtle finds its new position.
  2235.  
  2236. To change the colour of the drawing pen, use the COLOR command.
  2237.  
  2238. That's probably enough about Turtle Graphics. Oh by the way, if you want
  2239. to know more about the origins and uses of Logo, read Papert's "Mindstorms"
  2240. and his recent book entitled "The Children's Machine: Rethinking School in 
  2241. the Age of the Computer". They make for interesting reading.
  2242.  
  2243. While I think of it, Sherry Turkle wrote a book called "The Second Self: 
  2244. Computers and the human spirit", which I recommend if you're at all 
  2245. interested in the psychological/social effects of computing.
  2246.  
  2247.  
  2248. Loading & displaying IFF pictures
  2249. ---------------------------------
  2250. IFF graphics files can now be loaded and displayed with ACE by using 
  2251. a few simple commands and functions.
  2252.  
  2253. The short example program prgs/gfx/iff.b demonstrates typical usage.
  2254.  
  2255. IFF READ uses the freeware ILBM.library but you don't need to have this
  2256.  
  2257.                                   - page 37 -
  2258.  
  2259. since it will be created by ACE automatically at run-time if need be. If
  2260. LIBS:ilbm.library is not found at run-time ACE will use the library's binary 
  2261. image - which is stored in db.lib - to create ram:ILBMtmp/ilbm.library. This
  2262. file and the directory ILBMtmp will be removed when the program exits. The
  2263. idea of using a binary image like this was Roland Acton's.
  2264.  
  2265. See ref.doc for details of the IFF commands and function.
  2266.  
  2267.  
  2268. Sound
  2269. -----
  2270. ACE provides you with similar functionality as AmigaBASIC for sound
  2271. generation. It also allows you to do some things that AmigaBASIC doesn't.
  2272.  
  2273. See prgs/sound/sound.b for an example of how to use ACE's sound facilities 
  2274. in general.
  2275.  
  2276. How many times have you wished that AmigaBASIC would let you produce
  2277. white noise easily like the good ol' C64 and Vic-20 did?
  2278.  
  2279. Well, you'll be pleased to know that ACE allows you to do this. All you 
  2280. have to do is allocate about 4000 or more bytes of Chip RAM (upwards of 
  2281. 4000 bytes yields better quality white noise), poke it with random values 
  2282. (between -128 and 127), call WAVE and you're set (see sound.b)!
  2283.  
  2284. Moreover, you can actually play sound samples (IFF or otherwise) in the
  2285. same way, using just the two commands WAVE and SOUND (see prgs/sound/play.b). 
  2286.  
  2287. As with AmigaBASIC, a sine waveform is the default, but through the WAVE
  2288. statement you can create any waveform you wish including sawtooth, triangle, 
  2289. square and random (white noise).
  2290.  
  2291. WAVE has the following syntaxes:
  2292.  
  2293.     WAVE voice,SIN
  2294. and    
  2295.     WAVE voice,waveform-address,byte-count
  2296.  
  2297. where waveform-address is the start of a block of memory where the waveform
  2298. resides (an area of ALLOC'd CHIP memory) and byte-count is the number of bytes 
  2299. in the waveform table.
  2300.  
  2301. The SOUND statement syntax is as follows:
  2302.  
  2303.     SOUND period,duration[,volume][,voice]
  2304.  
  2305. This is different to AmigaBASIC in a number of ways. First, in ACE you
  2306. specify the sampling period NOT the frequency. This was easier to implement
  2307. and still provides the same functionality, but if you want specific notes, 
  2308. you'll have to do the calculations yourself (see equations below).
  2309.  
  2310. Sampling period is inversely proportional to frequency, so a high sampling
  2311. rate corresponds to a low frequency and vice-versa. ACE allows you to
  2312. specify a sampling period in the range 124..32767.
  2313.  
  2314. The duration is a single-precision value as in AmigaBASIC but can range from 
  2315. 0..999 (instead of 0..77). This range is somewhat arbitrary, but gives plenty
  2316. of scope for large sound samples. This specifies the length of time that a 
  2317.  
  2318.                                   - page 38 -
  2319.  
  2320. tone should be played for. A duration of 18.2 corresponds to about 1 second. 
  2321.  
  2322. Volume defaults to 64 if not specified and can range from 0..64.
  2323.  
  2324. The voice can be in the range 0..3 - since there are 4 audio channels - 
  2325. with 0 & 3 corresponding to the left speaker and 1 & 2 to the right.
  2326. The default voice is 0.
  2327.  
  2328. At the moment, ACE's SOUND statement isn't very good when used to produce a 
  2329. series of short pulses, although this is somewhat dependent upon the waveform 
  2330. in use. In any case, more work needs to be done in this area to prevent 
  2331. "popping" between SOUND statements when the audio hardware is turned on and 
  2332. off in rapid sequence.
  2333.  
  2334. ACE sound is produced by programming the hardware directly. A future version
  2335. will utilise the audio device instead. Indeed, the SOUND statement in ACE 
  2336. may change in the future to be more in line with AmigaBASIC (see also "Future 
  2337. Versions").
  2338.  
  2339. Finally, here's some useful equations for use in conjunction with ACE's SOUND 
  2340. statement:
  2341.  
  2342.     samples/second to period:
  2343.     ------------------------
  2344.     period = 3579546 / samples-per-second
  2345.     
  2346.     musical note to period:
  2347.     ----------------------
  2348.     period = 3579546 / (length * frequency)
  2349.  
  2350.     where length is the size of the waveform table in bytes 
  2351.     (32 bytes for ACE's sine waveform) and frequency is the
  2352.     note itself (eg: middle C is 523.25 Hz).
  2353.  
  2354.     duration value for one waveform cycle:
  2355.     -------------------------------------
  2356.     duration = .279365 * period * length / 1E6 * 18.2
  2357.  
  2358.         
  2359. Event trapping
  2360. --------------
  2361. ACE provides for AmigaBASIC-style event trapping. The following event 
  2362. types are supported:
  2363.  
  2364.     BREAK     -  user break: ctrl-c.
  2365.     MOUSE     -  left mouse button press.
  2366.     TIMER(n)  -  cause a trap every n seconds.
  2367.     ERROR      -  I/O and other errors.
  2368.     MENU      -  menu selection.
  2369.     WINDOW      -  window event: close-gadget click. 
  2370.     GADGET      -  user-defined gadget selection.
  2371.  
  2372. Event trapping in ACE works by checking for a given event at strategic points
  2373. in a program (before NEXT, WEND, GOTO, CALL, PRINT etc) and if an event is
  2374. detected, control is passed to a trap handling routine. Hence, trapping here
  2375. does not refer to CPU traps (exceptions).
  2376.  
  2377. Even if your program expects to do nothing but trap events, you'll need a
  2378.  
  2379.                                   - page 39 -
  2380.  
  2381. loop like this:
  2382.  
  2383.     WHILE -1
  2384.       SLEEP      '..don't hog the CPU  [SLEEP is optional but nice] 
  2385.     WEND
  2386.  
  2387. if you wish to have any events handled by your program.
  2388.  
  2389. The specification for the trapping of an event is: 
  2390.  
  2391.     ON <event> GOSUB | GOTO <label>|<line-number> (eg: ON BREAK GOTO quit)
  2392.  
  2393. which indicates the routine to which control is to be passed when an event
  2394. is trapped. This is followed at some stage by:
  2395.  
  2396.     <event> ON  (eg: BREAK ON)  
  2397.  
  2398. which causes the compiled program from that point UNTIL the trap handling 
  2399. routine, to contain event trapping code.
  2400.  
  2401. It is a good idea to put trap handlers at the end of a program, since once the
  2402. handler for an event is found by the compiler, no more event trapping code is
  2403. generated for that event even if there is code below the handing routine. In
  2404. other words, the equivalent of an <event> OFF (see below) command is issued 
  2405. once the trap handling code is found by the compiler. 
  2406.  
  2407. Other commands are:
  2408.  
  2409.     <event> STOP
  2410.  
  2411. which disables trapping for the event until another <event> ON is issued, 
  2412. and:
  2413.  
  2414.     <event> OFF
  2415.  
  2416. which disables trapping for the event permanently.
  2417.  
  2418. Just so there is no misunderstanding, the latter two commands prevent the 
  2419. inclusion of event trapping code for a specific event in your program at the 
  2420. assembly source level. They do this from the point in an ACE program at 
  2421. which they are issued.
  2422.  
  2423. Here's a typical example:
  2424.  
  2425.     ON BREAK GOTO quit
  2426.     BREAK ON
  2427.  
  2428.     for i=1 to 1000000
  2429.      print i
  2430.     next
  2431.  
  2432.     quit:
  2433.       PRINT "**break!"
  2434.       STOP
  2435.  
  2436. Simultaneous trapping of several different events is possible and in general
  2437. works very well. The use of INKEY$ and ON BREAK together when a user-defined 
  2438. window is the current output window leads to some competition. You may simply 
  2439.  
  2440.                                   - page 40 -
  2441.  
  2442. need to hit ctrl-c a few times in this circumstance for a user break to be 
  2443. accepted.
  2444.  
  2445. If you wish to trap only one kind of event you should consider the use of 
  2446. WAITing (only for menus and gadgets currently - see MENU/GADGET WAIT).
  2447.  
  2448.  
  2449. Interprocess Communication
  2450. --------------------------
  2451. ACE provides a simple IPC mechanism centered around a set of MESSAGE
  2452. commands (see ref.doc for full details).
  2453.  
  2454. ACEports represent a half-duplex, blocking/non-blocking, named IPC mechanism, 
  2455. similar to Berkeley Unix domain datagram sockets.
  2456.  
  2457. The mechanism is based upon Exec message ports and provides a simple way
  2458. for concurrently running ACE programs to communicate across unique, safe
  2459. channels. Strings can be sent as messages to a particular message port,
  2460. the name of which must be known in advance.
  2461.  
  2462. Probably the best way to find out how the MESSAGE commands are used
  2463. in ACE is to compile, run and study the programs in prgs/ACEports.
  2464.   
  2465. I consider this feature to be experimental and am interested in your 
  2466. feedback regarding it. The ACEports mechanism will probably be improved 
  2467. as time goes by.
  2468.  
  2469. ARexx capabilities are also planned for ACE at some stage.
  2470.  
  2471.  
  2472. Error Handling
  2473. --------------
  2474. The compiler messages generated by ACE are often different to the ones in the
  2475. AmigaBASIC interpreter (and ACE doesn't beep at you with each error) but they
  2476. are usually fairly clear.
  2477.  
  2478. Syntactically incorrect programs can lead ACE to produce a bunch of spurious 
  2479. error messages. In such cases, it's best to ignore all but the first one or 
  2480. two, unless there are "clusters" of messages which are separated by periods 
  2481. of error-free compilation.
  2482.  
  2483. If you leave out END IF, WEND, UNTIL, NEXT, END SUB, END STRUCT or END CASE, 
  2484. there will be a corresponding number of error messages at the end of the 
  2485. compile. If you leave off two WENDs, you'll get 2 "WHILE without WEND" error
  2486. messages.
  2487.  
  2488. ACE generally reports the first error in a line of code and ignores the rest 
  2489. of the "bad" line. A typical message consists of the line containing the error,
  2490. a carat ("^") marker, and the error message itself. More work still needs to 
  2491. be done on ACE's compile-time error handling, but it's bearable.
  2492.  
  2493. No error messages are issued by ACE programs at run-time. Generally, when a 
  2494. program runs into something it can't do, or an erroneous request - like
  2495. trying to open two files to the same file number or trying to open a library 
  2496. that doesn't exist - the program will either quit or just not have the desired 
  2497. effect. 
  2498.  
  2499. Note that while the ERR function and ON ERROR event trapping are supported,
  2500.  
  2501.                                   - page 41 -
  2502.  
  2503. only file I/O, serial I/O, IFF, IPC (MESSAGE) and window/screen open errors 
  2504. are currently reported via these mechanisms.
  2505.  
  2506.  
  2507. Notes for assembly programmers
  2508. ------------------------------
  2509. I've tried to make the assembly source files that ACE produces as 
  2510. readable as possible by using meaningful data object names. See also
  2511. "Compiler options" re: the compiler's "-c" switch.
  2512.  
  2513. Linked library routines use data registers d0-d6 and address registers 
  2514. a0-a3, while d7 is used for array index calculations. Also, a4 and a5 are 
  2515. used as stack frame pointers for variables and parameters.
  2516.  
  2517. Most db.lib routines don't save and restore registers via the stack, but 
  2518. the use of registers is internally consistent (ie: all registers are up for 
  2519. grabs but interdependent routines are written in such a way so as not to 
  2520. conflict). External function calls in ACE programs now _do_ save and restore 
  2521. registers.
  2522.  
  2523. The use of linked libraries means that the size of all executables is
  2524. fairly large. But given that disk space and memory are cheap, I'd rather
  2525. this than the alternative of having every executable be dependent upon one
  2526. or more special shared libraries at run-time. However, I will try to reduce
  2527. the size of executables. Some improvement has been made with the current
  2528. revision. Kendall Sears has suggested the creation of smaller versions of 
  2529. db.lib and startup.lib for use with shell-based programs. I like this idea
  2530. and will implement it when I have time.
  2531.  
  2532. Due to BASIC's tendency to coerce data types so much for the programmer,
  2533. the resulting code can look a little nasty, and big increases in efficiency 
  2534. can be gained by careful combinations of data types in expressions.
  2535.  
  2536. Writing ACE has so far been a learning experience for me and if when I started
  2537. I knew what I know now, I would have done many things differently.
  2538.  
  2539. My original rationale for passing parameters via registers to ACE (and shared) 
  2540. library functions was to improve execution speed. However, since I call lots 
  2541. of other functions (eg: in ami.lib) which require their parameters to be on 
  2542. the stack, I would probably call ALL functions in this way if I did it again. 
  2543.  
  2544. Moreover, my desire for internal consistency led me to a rather odd method of 
  2545. passing parameters to SUBs. This allowed me to treat parameters in the same way
  2546. as variables which is all very nice, but it led to other problems, chief among
  2547. them being the need to use a Forbid()/Permit() pair when sending parameters to 
  2548. a SUB. This works fine however, so I'm taking the view that if it 'aint broke,
  2549. I probably shouldn't fix it. 
  2550.  
  2551.  
  2552. Limitations
  2553. -----------
  2554. Undeclared variables do NOT get a default zero or NULL value, so don't
  2555. assume ANYTHING about the contents of an uninitialised variable, eg.
  2556.  
  2557.     PRINT X 
  2558.  
  2559. will yield garbage if X has not been given a value. The optional variable 
  2560. declarations provided in ACE are therefore worth using since they DO give
  2561.  
  2562.                                   - page 42 -
  2563.  
  2564. variables an initial zero or NULL value.
  2565.  
  2566. The precision of exponentiation begins to falter with large numbers (where 
  2567. the exponent is around 23 or higher) because all exponentiation is currently 
  2568. done with the single-precision math library function SPPow(). Use either long
  2569. integer multiplication or ACE's SHL function for greater accuracy, where
  2570. integers are applicable. For example, compare SHL(2,22) with INT(2^23). You
  2571. may also find that integer exponentiation sometimes yields a non-integer
  2572. result, eg.
  2573.  
  2574.     PRINT 2^3
  2575. gives:
  2576.     8.0000009
  2577.  
  2578. This is an artifact of single-precision exponentiation. I intend to make
  2579. ACE take a more intelligent approach to integer exponentiation in a future
  2580. revision (probably the next one).
  2581.  
  2582. If you are only interested in an integer result, apply CINT or CLNG, thus:
  2583.  
  2584.     PRINT CLNG(2^3)
  2585. to get:
  2586.     8 
  2587.  
  2588. See also the LONGINT(n) function for getting around the problem of extracting
  2589. a large integer value from a string.
  2590.  
  2591. While strings can be defined to be longer (or shorter) than 1K, there
  2592. are some ACE commands and functions which still assume a 1K limit, namely: 
  2593. STRING$, SPACE$, LINE INPUT#, INPUT and SWAP.
  2594.  
  2595. Strings and arrays which are local to a subprogram will be overwritten if
  2596. the SUB has recursive calls to itself. The same applies to string parameters. 
  2597. In all these cases a single static data item is being referenced.
  2598.    
  2599. If you issue RETURN from within a FOR loop, the return address will *not* be 
  2600. the top item on the stack. Instead, FOR..NEXT loop data will be. A GURU will 
  2601. almost certainly result. It is probably better to use a while or repeat loop 
  2602. if you must RETURN from within a loop. See also EXIT FOR in ref.doc which
  2603. allows for the safe, early termination of FOR loops.
  2604.  
  2605. A shared variable cannot be used as a FOR loop index in ACE. Any attempt to
  2606. do so will result in a compile-time error.
  2607.  
  2608. IF..THEN NEXT will not have the desired effect (it's bad coding anyway).
  2609. NEXT must always appear on a line by itself or as part of a multi-statement. 
  2610.  
  2611. ACE does not consider "=>" to be the same symbol as ">=". In fact, ACE 
  2612. doesn't recognise the former at all. The same is true of "=<".
  2613.  
  2614. The compiler only responds to ctrl-c during the main compilation phase, 
  2615. and not during optimisation or when target code is being written.
  2616.  
  2617. Don't mix the compiler's "b" option with BREAK event trapping, as they will
  2618. conflict.
  2619.  
  2620.  
  2621. Known Bugs
  2622.  
  2623.                                   - page 43 -
  2624.  
  2625. ---------- 
  2626. The SAY(n) *function* works under release 2.x but not under 1.3. Since the 
  2627. function uses no 2.x-specific code, this is puzzling. The SAY command works 
  2628. under both 1.3 and 2.x however.
  2629.  
  2630. A68K sometimes complains about string literal definitions produced by ACE 
  2631. if they are much longer than a single line.
  2632.  
  2633. Some fonts cause the INPUTBOX[$] display (string gadget) to be corrupted. 
  2634. Stick to topaz for this where possible. A future revision may use a 
  2635. GadTools or BOOPSI requester (for 2.x/3.x machines).
  2636.  
  2637.  
  2638. Future versions
  2639. ---------------
  2640. Random files and double-precision floating-point math are high on the agenda.
  2641.  
  2642. More graphics (eg: GET,PUT) commands and functions are planned and I also 
  2643. intend to fix any remaining differences between ACE and AmigaBASIC in this 
  2644. area. 
  2645.  
  2646. AGA screen modes are likely to be supported soon (especially since I recently
  2647. purchased an A1200 :).
  2648.  
  2649. I may provide support for sprites at some stage. 
  2650.  
  2651. Thus far, I've taken the approach of implementing what I most often use 
  2652. and what I have often wished for in BASIC.
  2653.  
  2654. In recent times I have been impressed by three things in the programming 
  2655. world: the rise of Object-Oriented Programming (OOP), Resources (as found
  2656. on the Macintosh and MS-Windows) and Visual BASIC for Windows.
  2657.  
  2658. The idea of resources (pioneered by the Macintosh resource fork and
  2659. ResEdit) is a powerful one and Microsoft and Borland have picked up 
  2660. on this in MS-Windows. I wish the Amiga had them as standard, but alas 
  2661. it doesn't.
  2662.  
  2663. I am trying to add more "visual" stuff to ACE, hence: gadgets, menus,
  2664. requesters, AIDE. You can expect to see more "visualising" of ACE as time
  2665. goes by, including a GUI designer for ACE programs. To make ACE like Visual 
  2666. BASIC would take a major rewrite, but I can at least try to take advantage 
  2667. of some of its features.
  2668.  
  2669.  
  2670. A note to PD libraries and reviewers
  2671. ------------------------------------
  2672. First, to those magazines who have reviewed ACE so far, let me say a big 
  2673. THANK YOU. Good publicity is always appreciated as is acknowledgement of 
  2674. the time I've spent on ACE.
  2675.    
  2676. I'd appreciate it if you would check with me (if possible) to ensure you
  2677. have the latest version of ACE before including it in your library or
  2678. reviewing it for a magazine. If you don't have e-mail access, I don't
  2679. expect you to do this (snail-mail is a pain isn't it!?).
  2680.  
  2681. Lastly, the wider ACE travels the happier I am, so I'm pleased to see
  2682. ACE turning up in the odd PD library. Please note however that I don't
  2683.  
  2684.                                   - page 44 -
  2685.  
  2686. wish people to profit financially from the distribution of ACE. You may
  2687. charge a fee which covers the cost of the disk and the copying thereof,
  2688. but no more.
  2689.  
  2690.  
  2691. Disclaimer
  2692. ----------
  2693. Although every care has been taken in the development and testing of the 
  2694. compiler and its libraries, the author will not be held liable for damages 
  2695. caused either directly or indirectly as a result of the use of ACE.
  2696.  
  2697.  
  2698. References
  2699. ----------
  2700. The following references have been used in developing ACE:
  2701.  
  2702. +----------------------------------------------------------------------------+
  2703. | "Amiga BASIC" (manual), 1985, Commodore-Amiga Inc. and Microsoft Inc.      |
  2704. |                                         |
  2705. | "Amiga ROM Kernel Reference Manual: Libraries", 1992, Commodore-Amiga         |
  2706. |                                         |
  2707. | "Amiga ROM Kernel Reference Manual: Devices", 1991, Commodore-Amiga         |
  2708. |                                         |
  2709. | Anderson & Thompson, 1990, "Mapping the Amiga", COMPUTE! Publications Inc. |
  2710. |                                         |
  2711. | Bleek, Jenrich & Schulz, 1989, "Amiga C for Advanced Programmers", Abacus  |
  2712. |                                         |
  2713. | Choi, 1990, "Advanced Programming Techniques", University of Tasmania      |
  2714. |                                         |
  2715. | Dittrich, 1989, "Amiga Machine Language", Abacus                 |
  2716. +----------------------------------------------------------------------------+
  2717.  
  2718. Despite its not infrequent errors, "Mapping the Amiga" remains an excellent 
  2719. resource. I have also often referenced "Advanced Amiga C programming". 
  2720.  
  2721. Naturally, the two RKM volumes listed above and the "Amiga BASIC" manual are 
  2722. used regularly as well.
  2723.   
  2724. Although not listed, Commodore's Autodocs for the Amiga (supplied with the
  2725. Native Developer Kit) are also constantly used.
  2726.  
  2727. Young Choi's Advanced Programming notes in many ways provided the impetus
  2728. for the development of ACE. They were used in a compiler construction course
  2729. I took as an undergraduate. I thank Young for introducing me to the joys
  2730. of compiler writing, although I know he didn't intend me to spend *all* my
  2731. time writing programming language translators of one kind or another. :-)
  2732.  
  2733. Including the Pascal Minus compiler I wrote for that course, and the PC BASIC 
  2734. interpreter I wrote during the same period, I've since written a version of
  2735. Logo (turtle graphics subset), a Forth interpreter and ACE.
  2736.  
  2737.  
  2738. Contacting the author
  2739. ---------------------
  2740.  
  2741. I am contactable via e-mail on: the Internet, Compuserve and Discovery 40/80.
  2742. Of course, there is also the telephone and snail-mail.
  2743.  
  2744.  
  2745.                                   - page 45 -
  2746.  
  2747. +-----------------------------------------------+
  2748. |     Internet: D.Benn@appcomp.utas.edu.au     |
  2749. |                        |
  2750. |   Compuserve: 100033,605                  |
  2751. |                        |
  2752. | Discovery 40: 032432850            |
  2753. |                        |
  2754. |      Phone: (003) 317 680 [home]              |
  2755. |          (003) 243 529 [work]              |
  2756. |                              |
  2757. |    Address: 181 St John Street, Launceston,     |               
  2758. |          Tasmania, Australia, 7250              |
  2759. +-----------------------------------------------+
  2760.  
  2761.  
  2762. ACE discussion list and FTP site
  2763. --------------------------------
  2764. In February 1994 I was allowed to establish a listserver-based discussion 
  2765. list for ACE on one of the Unix boxes at my place of work, the University 
  2766. of Tasmania at Launceston's Department of Applied Computing and Mathematics.
  2767.  
  2768. The purpose of the list is to allow for the dissemination of information 
  2769. about ACE, the discussion of bugs, problems, solutions and ACE programming 
  2770. in general.
  2771.  
  2772. To subscribe to the list send (Internet) e-mail to:
  2773.  
  2774.     Listserver@appcomp.utas.edu.au
  2775.  
  2776. The subject-line of the message is unimportant, but the first line of the 
  2777. message must be of the following format:
  2778.  
  2779.     subscribe ace FirstName LastName
  2780.  
  2781. For example, in my case:
  2782.  
  2783.     subscribe ace David Benn
  2784.  
  2785. would do the trick. The listserver will send you a welcome message and
  2786. information about how to participate in the list.
  2787.  
  2788. At about the same time as the ACE list was established, an anonymous FTP
  2789. server was set up:
  2790.  
  2791.     ftp.appcomp.utas.edu.au
  2792.  
  2793. ACE-related files are stored in the directory:
  2794.  
  2795.     /pub/amiga/ACE
  2796.  
  2797. I'd like to thank Tony Gray (Technical Services Manager) and Christian
  2798. McGee for maintaining the listserver and Young Choi (Head of Department) 
  2799. for allowing me to use the department's facilities for this purpose.
  2800.  
  2801.  
  2802. Final word
  2803. ----------
  2804. Let me offer my thanks to Charlie Gibbs for his reliable assembler and to 
  2805.  
  2806.                                   - page 46 -
  2807.  
  2808. the Software Distillery for Blink. Without these excellent programs, far 
  2809. fewer compilers would have seen the light of day, including ACE.
  2810.  
  2811. Sozobon C (ZC) has always been a reliable workhorse for me, so a vote of
  2812. thanks goes to Sozobon as well. Isn't freeware great?
  2813.  
  2814. I'd like to thank those people who have tested ACE so far. They are too 
  2815. numerous to mention here, but special thanks goes to Addison Laurent, 
  2816. Alan-Peyton Smith, Peter Zielinski, John Stiwinter and the members of
  2817. the ACE discussion list (see above).
  2818.  
  2819. These guys have given ACE a good workout on a variety of platforms ranging 
  2820. from an A1000 running Wb 1.3 to 68030 machines running Wb 3.0.
  2821.  
  2822. I'd especially like to thank Michael Zielinski for discovering a particularly 
  2823. serious bug which prevented branches of greater than 32K in length prior
  2824. to v1.02. Also, Enforcer hits reported by him started me on a trail which
  2825. led to a nasty string-related bug (see entry for 13/4/93 in docs/history).
  2826.  
  2827. Jarto 'Robin' Tarp pointed out how inefficient my first implementation
  2828. of INSTR was. It's considerably faster now (since v1.02).
  2829.  
  2830. Let me stress that any remaining bugs in ACE are entirely my fault.
  2831.  
  2832. Others have given me a great deal of encouragement and made useful comments 
  2833. throughout 1993 and 1994. I hope this continues. The sense of community on
  2834. the virtual world of the Net is a refreshing change from the general weirdness
  2835. of the "real" world.
  2836.  
  2837. I'd like to thank John Stiwinter for all his excellent work in putting
  2838. together the AmigaGuide documents for ACE. Having ACE's reference material
  2839. in this format has enhanced its utility enormously. He has also done 
  2840. other stuff in the background for which I am grateful.
  2841.  
  2842. Many of the subscribers to the ACE discussion list (see above section) 
  2843. have given me plenty to think about, plenty of bug reports and plenty of 
  2844. support. In particular, thanks goes to Kendall Sears for keeping me on my 
  2845. toes and for providing expert technical knowledge of the Amiga.
  2846.  
  2847. Jeff Harris, Chuck Kenney, Dan Oberlin, Sean Miller and Kenneth Brill have 
  2848. all contributed to ACE in their own ways. Thanks guys! Also, to all those 
  2849. who have e-mailed or written to me, thanks. You know who you are!
  2850.  
  2851. I'd also like to thank my wife Karen, for her encouragement and support, 
  2852. for putting up with the number of hours I spend at the computer, and
  2853. just for tolerating me generally. :-)  IFS is her favourite program so 
  2854. it's dedicated to her (try the "Green Fern").
  2855.  
  2856. Despite ACE's problems (see "Limitations" and "Known Bugs") it is proving
  2857. to be a useful tool for me, and if others can derive benefit from it, well, 
  2858. that's great. ACE is gradually coming to support the features I and others 
  2859. want it to, but there's still plenty of work to do.
  2860.  
  2861. The provision of support for shared library functions, external functions, 
  2862. machine code routines, inline assembly code, include files and linkable 
  2863. SUB modules should go a long way towards making up for ACE's intrinsic 
  2864. shortcomings.
  2865.   
  2866.  
  2867.                                   - page 47 -
  2868.  
  2869. I hope you enjoy ACE and find it useful. I'm learning a great deal by 
  2870. developing it and having a lot of fun in the process. If you feel the need
  2871. to send me some money, please go ahead, but I certainly don't expect it.
  2872.  
  2873. What I DO want is feedback. If you have any problems, requests, queries or 
  2874. suggestions, I want to hear from you and I'd like to hear about interesting 
  2875. programs you've written with ACE (send me the source code if you like). I'm
  2876. always on the lookout for good example programs to include in the ACE archive.
  2877.  
  2878. Remember that ACE is FreeWare, so redirect flames to NIL:  :^).
  2879.  
  2880. Happy programming!
  2881.  
  2882. Regards, David Benn
  2883. 22nd October 1994
  2884.  
  2885.  
  2886.  
  2887.  
  2888.  
  2889.  
  2890.  
  2891.  
  2892.  
  2893.  
  2894.  
  2895.  
  2896.  
  2897.  
  2898.  
  2899.  
  2900.  
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908.  
  2909.  
  2910.  
  2911.  
  2912.  
  2913.  
  2914.  
  2915.  
  2916.  
  2917.  
  2918.  
  2919.  
  2920.  
  2921.  
  2922.  
  2923.  
  2924.  
  2925.  
  2926.  
  2927.  
  2928.                                   - page 48 -
  2929.